[Python-3000] self-contained exceptions

Adam Olsen rhamph at gmail.com
Wed Jan 3 18:41:52 CET 2007

On 1/2/07, Guido van Rossum <guido at python.org> wrote:
> > On 1/1/07, Guido van Rossum <guido at python.org> wrote:
> > > will introduce a cycle from err -> traceback -> stack frame -> err,

> The problem with a weakref is that it won't keep the tb alive when you
> save the exception for later (as is done for instance by the unittest
> module). So it is of limited value and could even be confusing. OTOH
> it *does* remove the need to call sys.exc_info() in the most common
> case, so I don't want to rule it out completely.

That can be solved by moving the weakref to the stack frame -> exc
part, and only turning it from a strong reference into a weak
reference when the function exits.  When debugging via the raised
exception, the chain of __context__ references would keep it alive.

The disadvantage is it requires the local variable created by "except
Exception, exc" be special, perhaps not allowing any further
assignment to it or other limitations.

Adam Olsen, aka Rhamphoryncus

More information about the Python-3000 mailing list