Exception Handling in Python 3
Martin v. Loewis
martin at v.loewis.de
Sun Oct 24 04:48:23 EDT 2010
Am 24.10.2010 07:01, schrieb Steve Holden:
> I was somewhat surprised to discover that Python 3 no longer allows an
> exception to be raised in an except clause (or rather that it reports it
> as a separate exception that occurred during the handling of the first).
I think you are misinterpreting what you are seeing. The exception being
raised actually *is* an attribute error, and it actually is the
attribute error that gets reported. It's only that reporting an
exception that has a __context__ first reports the context, then reports
the actual exception.
You may now wonder whether it is possible to set __context__ to None
somehow. See PEP 3134:
Open Issue: Suppressing Context
As written, this PEP makes it impossible to suppress '__context__',
since setting exc.__context__ to None in an 'except' or 'finally'
clause will only result in it being set again when exc is raised.
Regards,
Martin
More information about the Python-list
mailing list