"reraise" & Exception Transformation (was Re: Modules implicitly exposing exceptions from other modules)

Greg Ewing greg at cosc.canterbury.ac.nz
Mon Feb 21 22:32:02 EST 2000


Bernhard Herzog wrote:
> 
>      *Warning:* assigning the TRACEBACK return value to a local
>      variable in a function that is handling an exception will cause a
>      circular reference...
> 
> So, a better way to reraise the exception is
> 
> def baz():
>     try:
>         bar()
>     except NameError:
>         raise AttributeError, None, sys.exc_info()[-1]

This is a lot of tricky stuff to remember and get right,
which discourages one from using this technique as often
as one should. It would be nice if there were a simple
variation on the "raise" statement which meant "raise
this exception using the previous traceback".

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



More information about the Python-list mailing list