Re: catching exceptions from an except: block
En Fri, 09 Mar 2007 04:49:59 -0300, Gerard Flanagan
<grflanagan@yah oo.co.ukescribi ó:
As back in time as I could go (Python 1.5), exceptions were available as
builtins...
There is a serious flaw on this approach, the function can't return any
false value (it would be treated as a failure).
--
Gabriel Genellina
En Fri, 09 Mar 2007 04:49:59 -0300, Gerard Flanagan
<grflanagan@yah oo.co.ukescribi ó:
Another version:
>
import exceptions
>
import exceptions
builtins...
def onfailFalse(fn) :
def inner(*args, **kwargs):
try:
return fn(*args, **kwargs)
except ABCException:
return False
return inner
>
@onfailFalse
def a(x):
if x == 1:
return 'function a succeeded'
else:
raise ABCException()
def inner(*args, **kwargs):
try:
return fn(*args, **kwargs)
except ABCException:
return False
return inner
>
@onfailFalse
def a(x):
if x == 1:
return 'function a succeeded'
else:
raise ABCException()
false value (it would be treated as a failure).
--
Gabriel Genellina
Comment