How to propagate an exception ?

Emile van Sebille emile at fenx.com
Sat May 18 08:52:15 EDT 2002


Shagshag
> How do you propagate an exception ? Is there a way to raise the
> previous exception raised after doing something ?
> 

use raise by itself to re-raise the prior error:

>>> def test():
...     try:
...             1/0
...     except ZeroDivisionError:
...             raise
...
>>> test()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "<stdin>", line 3, in test
ZeroDivisionError: integer division or modulo by zero
>>>


--

Emile van Sebille
emile at fenx.com

---------




More information about the Python-list mailing list