EAFP vs LBYL (was Re: A little disappointed so far)
Gerhard Häring
gh at ghaering.de
Mon May 19 15:39:47 EDT 2003
Carl Banks wrote:
> 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
Isn't the "except: raise" implicit if you omit it?
-- Gerhard
More information about the Python-list
mailing list