EAFP vs LBYL (was Re: A little disappointed so far)

Carl Banks imbosol at aerojockey.com
Mon May 19 15:31:00 EDT 2003


Alex Martelli wrote:
> Bare except is definitely NOT what I'm advocating, of course.  I don't
> think I've ever caught anything broader than StandardError in production
> code, actually (except in weird cases to accomodate 'host code' that
> might be raising strings, was specifically untrusted, and the like) --
> and when I do catch so widely is typically one of the few cases where
> I'll use isinstance, in order to reraise at once if I've happened to
> catch a KeyboardInterrupt (why the [expletive deleted] KeyboardInterrupt
> couldn't have been taken away from the part of the subtree derived from
> StandardError, I definitely dunno).


Out of curiosity, why not do this?

    try:
        ...
    except KeyboardInterrupt:
        handle_interrupt()
    except:
        raise


-- 
CARL BANKS




More information about the Python-list mailing list