File tree Expand file tree Collapse file tree 2 files changed +10
-8
lines changed Expand file tree Collapse file tree 2 files changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -1372,6 +1372,7 @@ except (<exception>, ...):
1372
1372
except (< exception> , ... ) as < name> :
1373
1373
```
1374
1374
* ** Also catches subclasses of the exception.**
1375
+ * ** Use ` 'traceback.print_exc()' ` to print the the error message.**
1375
1376
1376
1377
### Raising Exceptions
1377
1378
``` python
@@ -1390,11 +1391,11 @@ except <exception> as <name>:
1390
1391
### Exception Object
1391
1392
``` python
1392
1393
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__
1395
1395
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__ )
1398
1399
```
1399
1400
1400
1401
### Built-in Exceptions
Original file line number Diff line number Diff line change 1294
1294
1295
1295
< ul >
1296
1296
< 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 >
1297
1298
</ ul >
1298
1299
< div > < h3 id ="raisingexceptions "> Raising Exceptions</ h3 > < pre > < code class ="python language-python hljs "> < span class ="hljs-keyword "> raise</ span > <exception>
1299
1300
< span class ="hljs-keyword "> raise</ span > <exception>()
1306
1307
</ code > </ pre > </ div >
1307
1308
1308
1309
< div > < h3 id ="exceptionobject "> Exception Object</ h3 > < pre > < code class ="python language-python hljs "> arguments = <name>.args
1309
- line_number = <name>.__traceback__.tb_lineno
1310
- func_name = <name>.__traceback__.tb_frame.f_code.co_name
1310
+ exc_type = <name>.__class__
1311
1311
filename = <name>.__traceback__.tb_frame.f_code.co_filename
1312
- line = linecache.getline(filename, line_num)
1313
- error_msg = traceback.format_exc()
1312
+ func_name = <name>.__traceback__.tb_frame.f_code.co_name
1313
+ line = linecache.getline(filename, <name>.__traceback__.tb_lineno)
1314
+ error_msg = traceback.format_exception(exc_type, <name>, <name>.__traceback__)
1314
1315
</ code > </ pre > </ div >
1315
1316
1316
1317
< div > < h3 id ="builtinexceptions "> Built-in Exceptions</ h3 > < pre > < code class ="text language-text "> BaseException
You can’t perform that action at this time.
0 commit comments