Destructors and exceptions

Duncan Booth me at privacy.net
Wed Jun 9 04:42:36 EDT 2004


dkturner at telkomsa.net (David Turner) wrote in
news:e251b7ba.0406082329.f0692fd at posting.google.com: 

>> When an exception is handled, you can access the stack traceback.
>> This contains references to all the local variables which were in
>> scope at the point when the exception was thrown. Normally these
>> variables would be destroyed when the functions return, but if there
>> is a traceback referencing them they stay alive as long as the
>> traceback is accessible which is usually until the next exception is
>> thrown. 
> 
> Then why not unreference the traceback (and therefore destroy it and
> the down-stack locals, if the exception handler hasn't made another
> reference) at the end of the handling suite?

Fine, except that isn't what Python does now, and the current behaviour 
needs to be kept for compatibility. So if that is the behaviour you want, 
you have to do that explicitly yourself at the end of every exception 
handler.



More information about the Python-list mailing list