catching exceptions from an except: block

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Thu Mar 8 21:33:54 EST 2007


En Thu, 08 Mar 2007 21:11:54 -0300, Steven D'Aprano  
<steve at REMOVEME.cybersource.com.au> escribió:

>>> @onfail(False)
>>> def a(x):
>>>     if x == 1:
>>>         return 'function a succeeded'
>>>     else:
>>>         raise
>
> I thought "raise" on its own was supposed to re-raise the previous
> exception, but I've just tried it in the interactive interpreter and it
> doesn't work for me.

Not the *previous* exception, but the *current* one. You must be inside an  
"except" clause to use a bare raise.

-- 
Gabriel Genellina




More information about the Python-list mailing list