[issue2833] __exit__ silences the active exception
Antoine Pitrou
report at bugs.python.org
Wed May 14 11:21:37 CEST 2008
Antoine Pitrou <pitrou at free.fr> added the comment:
As Amaury said, lexically nested exception handlers make re-raising
behaviour buggy. In Py3k, a workaround is to instead write:
try:
raise Exception("foo")
except Exception as :
try: raise KeyError("caught")
except KeyError: pass
raise e
With the slight inconvenience that the "raise e" line will be appended
to the original traceback.
If we want bare "raise" statements to work as expected after a nested
exception handler, we'll need to add proper exception stacking, for
example by adding the exception value as a member of PyTryBlock. The
effect on performance should also be measured.
__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2833>
__________________________________
More information about the Python-bugs-list
mailing list