Message196344
Consider this:
$ python3 test_exc.py
Traceback (most recent call last):
File "test_exc.py", line 14, in <module>
fail1()
File "test_exc.py", line 11, in fail1
fail2()
File "test_exc.py", line 5, in fail2
raise RuntimeError('Third') from None
RuntimeError: Third
$ cat test_exc.py
def fail2():
try:
raise RuntimeError('Second')
except RuntimeError:
raise RuntimeError('Third') from None
def fail1():
try:
raise RuntimeError('First')
except:
fail2()
raise
fail1()
Any exception raised in fail2() is the immediate consequence of the 'First' exception should thus be chained to the 'First' exception.
However, if somewhere in the call stack under fail2() an exception is caught and re-raised from None (to convert between exception types), this also results in a loss of the chain to the initial exception.
The correct stacktrace (in my opinion) would be:
Traceback (most recent call last):
File "test_exc.py", line 9, in fail1
raise RuntimeError('First')
RuntimeError: First
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test_exc.py", line 14, in <module>
fail1()
File "test_exc.py", line 11, in fail1
fail2()
File "test_exc.py", line 5, in fail2
raise RuntimeError('Third')
RuntimeError: Third |
|
Date |
User |
Action |
Args |
2013-08-28 02:42:07 | nikratio | set | recipients:
+ nikratio |
2013-08-28 02:42:07 | nikratio | set | messageid: <1377657727.9.0.627993776621.issue18861@psf.upfronthosting.co.za> |
2013-08-28 02:42:07 | nikratio | link | issue18861 messages |
2013-08-28 02:42:07 | nikratio | create | |
|