[Python-Dev] Exception masking/chaining

Greg Ewing greg@cosc.canterbury.ac.nz
Fri, 13 Jun 2003 12:31:12 +1200 (NZST)


Guido:

> There's a lot of C code out there that catches e.g. AttributeError and
> replaces it with a more specific error (e.g. BifurcationError("can't
> bifurcate the sploorg") replacing AttributeError("__bifurcate__").  I
> think this would cause end user confusion.

But that is a different case. As I understand it, chaining would only
occur if a second exception was raised *before* the current exception
was caught -- e.g. if there's a bug in a piece of code in a finally
block that's being executed while unwinding to find an exception
handler.

In the case you're talking about, the AttributeError has been caught
by the time the BifurcationError is raised, so there would be no
chaining, and thus the traceback output would be the same regardless
of whether chained tracebacks were printed or not.

As for whether chained tracebacks should be printed when they occur,
I'll have to think about that. If they are, probably the one for the
most recently raised exception should be printed last, since one tends
to look at the bottom of the traceback first to find the cause of the
immediate problem (I do, at least).

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg@cosc.canterbury.ac.nz	   +--------------------------------------+