catching exceptions from an except: block

Bruno Desthuilliers bruno.42.desthuilliers at wtf.websiteburo.oops.com
Thu Mar 8 03:05:42 EST 2007


MonkeeSage a écrit :
> On Mar 7, 4:58 pm, Bruno Desthuilliers
> <bdesth.quelquech... at free.quelquepart.fr> wrote:
>>    except_retry: # the missing(???) keyword you're after
> 
> What is 'except_retry'?

A totally imaginary statement that would do what the OP is looking for.

> To the OP, with the loop and the callables you could also break out of
> the loop when the condition is met and use the else condition to raise
> the exception.
> 
> def test(arg):
>     for f in int, float, str, hex:
>         try:
>             return f(arg)
>             break # breaks on f==str

You don't need to break here since you're returning.

>         except:
>             pass
>     else:
>         raise ValueError # remove str above to see this



More information about the Python-list mailing list