[Python-3000] self-contained exceptions

Phillip J. Eby pje at telecommunity.com
Thu Jan 4 05:04:01 CET 2007

At 07:38 PM 1/3/2007 -0800, Guido van Rossum wrote:
>On 1/3/07, Ka-Ping Yee <python at zesty.ca> wrote:
> > On Wed, 3 Jan 2007, Adam Olsen wrote:
> > > 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.
> >
> > That seems like a reasonable approach to me.  The implementation
> > might be tricky, but the behaviour sounds correct.
>Which reference are you exactly turning into a weak ref? The hidden
>reference in the frame's f_exc_traceback? Or the variable 'err' in
>   except Exception, err: ...
>? The former goes away anyway so I'm not sure that this helps. And the
>latter seems fraught with peril; how do we even know which variables
>to treat this way? And why isn't it just as good to simply *delete*
>all locals that ever occurred in such a position in an except clause?

Or perhaps translate blocks of the form:

     except ExcType, e:
         # body


     except ExcType, e:
             # body
             del e

This won't stop you from creating a cycle explicitly, of course, but it 
would ensure that the simple cases would be cycle-free.

More information about the Python-3000 mailing list