Skip to content

Commit d598b43

Browse files
committed
Exceptions
1 parent afd1d64 commit d598b43

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,6 +1372,7 @@ except (<exception>, ...):
13721372
except (<exception>, ...) as <name>:
13731373
```
13741374
* **Also catches subclasses of the exception.**
1375+
* **Use `'traceback.print_exc()'` to print the the error message.**
13751376

13761377
### Raising Exceptions
13771378
```python
@@ -1390,11 +1391,11 @@ except <exception> as <name>:
13901391
### Exception Object
13911392
```python
13921393
arguments = <name>.args
1393-
line_number = <name>.__traceback__.tb_lineno
1394-
func_name = <name>.__traceback__.tb_frame.f_code.co_name
1394+
exc_type = <name>.__class__
13951395
filename = <name>.__traceback__.tb_frame.f_code.co_filename
1396-
line = linecache.getline(filename, line_num)
1397-
error_msg = traceback.format_exc()
1396+
func_name = <name>.__traceback__.tb_frame.f_code.co_name
1397+
line = linecache.getline(filename, <name>.__traceback__.tb_lineno)
1398+
error_msg = traceback.format_exception(exc_type, <name>, <name>.__traceback__)
13981399
```
13991400

14001401
### Built-in Exceptions

index.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,6 +1294,7 @@
12941294

12951295
<ul>
12961296
<li><strong>Also catches subclasses of the exception.</strong></li>
1297+
<li><strong>Use <code class="python hljs"><span class="hljs-string">'traceback.print_exc()'</span></code> to print the the error message.</strong></li>
12971298
</ul>
12981299
<div><h3 id="raisingexceptions">Raising Exceptions</h3><pre><code class="python language-python hljs"><span class="hljs-keyword">raise</span> &lt;exception&gt;
12991300
<span class="hljs-keyword">raise</span> &lt;exception&gt;()
@@ -1306,11 +1307,11 @@
13061307
</code></pre></div>
13071308

13081309
<div><h3 id="exceptionobject">Exception Object</h3><pre><code class="python language-python hljs">arguments = &lt;name&gt;.args
1309-
line_number = &lt;name&gt;.__traceback__.tb_lineno
1310-
func_name = &lt;name&gt;.__traceback__.tb_frame.f_code.co_name
1310+
exc_type = &lt;name&gt;.__class__
13111311
filename = &lt;name&gt;.__traceback__.tb_frame.f_code.co_filename
1312-
line = linecache.getline(filename, line_num)
1313-
error_msg = traceback.format_exc()
1312+
func_name = &lt;name&gt;.__traceback__.tb_frame.f_code.co_name
1313+
line = linecache.getline(filename, &lt;name&gt;.__traceback__.tb_lineno)
1314+
error_msg = traceback.format_exception(exc_type, &lt;name&gt;, &lt;name&gt;.__traceback__)
13141315
</code></pre></div>
13151316

13161317
<div><h3 id="builtinexceptions">Built-in Exceptions</h3><pre><code class="text language-text">BaseException

0 commit comments

Comments
 (0)