[Python-Dev] PEP 344: Exception Chaining and Embedded Tracebacks

Brett C. bac at OCF.Berkeley.EDU
Tue May 17 01:48:42 CEST 2005


Guido van Rossum wrote:
[SNIP - bunch of points from Guido]
> Do we really need both __context__ and __cause__?  Methinks that you
> only ever need one: either you explicitly chain a new exception to a
> cause, and then the context is probably the same or irrelevant, or you
> don't explicitly chain, and then cause is absent.  Since the traceback
> printing code is to prefer __cause__ over __context__, why can't we
> unify these?  About the only reason I can think of is that with
> __cause__ you know it was intentional and with __context__ you know it
> wasn't; but when is it important knowing the difference?
> 

I am with Guido.  I don't think the need to know if an exception was chained
explicitly or implicitly will be important enough to warrant a separate
attribute.  And if people care that much that can tack on a random attribute
like explicit_chain or something to the exception on their own.

[SNIP]
> In Java, I often find the way chained tracebacks are printed
> confusing, because the "deepest" stack frame (where the exception
> originally occurred) is no longer at the top of the printout.  I
> expect the same confusion to happen for Python, since it prints
> everything in the exact opposite order as Java does, so again the
> original exception is somewhere in the middle.  I don't think I want
> to fix this by printing the outermost exception first and the chained
> exception later (which would keep the stack frames in their proper
> order but emphasizes the low-level exception rather than the one that
> matches the except clause that would have caught it at the outermost
> level), but I might want to add an extra line at the very end (and
> perhaps at each chaining point) warning the user that the exception
> has a chained counterpart that was printed earlier.
> 

Just a simple "[chained exception]" note or something?  Sounds good.

[SNIP]
> You should probably reference the proposal (pending a PEP; I think
> Brett is working on it?)

My plan is to write the "Exceptions in Python 3000" PEP shortly after I start
my internship.  Going to put that at a higher priority than the AST branch to
make sure I get to it some time before I leave the country.  =)

-Brett


More information about the Python-Dev mailing list