catching exceptions from an except: block
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Fri Mar 9 03:56:40 EST 2007
En Fri, 09 Mar 2007 04:49:59 -0300, Gerard Flanagan
<grflanagan at yahoo.co.uk> escribió:
> Another version:
>
> import exceptions
As back in time as I could go (Python 1.5), exceptions were available as
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()
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
More information about the Python-list
mailing list