Dealing with exceptions
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Sat Mar 2 19:41:09 EST 2013
On Sat, 02 Mar 2013 18:52:19 +0100, Kwpolska wrote:
> Also, you can do `except:` for a catch-all, but it is discouraged unless
> you have REALLY good reasons to do this. And, most of the time, you
> don’t.
`except Exception` is to be much preferred over a bare except. It
excludes KeyboardInterruptError (the user hits Ctrl-C) and SystemExit,
which you normally either want to let through, or handle separately.
But yes, in general, only catch the minimum you *know* you need to catch
and can deal with. Anything else is a bug in your code that needs to be
fixed, and you can't fix it if you never see the exception.
--
Steven
More information about the Python-list
mailing list