[issue4486] Exception traceback is incorrect for strange exception handling

Nick Coghlan report at bugs.python.org
Tue Dec 2 21:49:55 CET 2008


Nick Coghlan <ncoghlan at gmail.com> added the comment:

Note that the display is correct in the case where the chaining is
"right", i.e.:

try:
  raise IOError
except:
  try:
    raise KeyError
  except Exception as ex:
    raise AttributeError from ex

In that case, IOError is correctly flagged as the original exception,
with a KeyError then occurring during the IOError handling, and the
KeyError then directly causing the AttributeError.

The weird thing I am doing in the example here is to set the __cause__
of the exception I am raising to an exception that was never itself
actually raised (the "from KeyError" bit).

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4486>
_______________________________________


More information about the Python-bugs-list mailing list