On Mar 9, 9:56 am, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Fri, 09 Mar 2007 04:49:59 -0300, Gerard Flanagan > <[EMAIL PROTECTED]> escribió: > > > Another version: > > > import exceptions > > As back in time as I could go (Python 1.5), exceptions were available as > builtins... >
I did not know that. Thanks. > > 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). > I was teaching myself decorators more than anything, so it's not thought out to any extent, but even so I don't think it's a "serious flaw", rather it would be programmer error to use @onfailFalse on a function that may return False. Don't you think? Gerard -- http://mail.python.org/mailman/listinfo/python-list