Re-throwing an exception without loosing the stack trace

Clark C . Evans cce at clarkevans.com
Tue Feb 12 18:08:29 EST 2002


| when you are finished cleaning up you can just execute the 
| raise statement with no arguments. 

How simple.  *blush*

Yes.  I didn't try using raise without any arguments.  Cool.
Funny, this isn't in Learning Python... and raise all by
itself isn't listed in the syntax in the book.  Hmm.

Thank you _so_ much.

Best,

;) Clark

>>> def x():
...     raise "hi"
...
>>> def y():
...    try:
...       x()
...    except:
...       print "hi"
...       raise
...
>>> def z():
...    y()
...
>>> z()
hi
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "<stdin>", line 2, in z
  File "<stdin>", line 3, in y
  File "<stdin>", line 2, in x
hi




More information about the Python-list mailing list