try... except with unknown error types

Chris Angelico rosuav at gmail.com
Sun Aug 21 15:17:59 EDT 2011


On Sun, Aug 21, 2011 at 7:26 PM, Paul Rubin <no.email at nospam.invalid> wrote:
> I'm not sure what to do instead.  The exceptions I'm currently dealing
> with happen when certain network operations go wrong (e.g. network or
> remote host is down, connection fails, etc.)  The remedy in each case is
> to catch the exception, log the error, and try the operation again
> later.  But there's no guaranteed-to-be-complete list in the Python docs
> of all the exceptions that can be thrown.  A new and surprising mode of
> network failure can lead to an unhandled exception, unless you catch
> everything.
>

A new and surprising mode of network failure would be indicated by a
new subclass of IOError or EnvironmentError. If you catch one of
those, you should catch it. That's the benefit of hierarchical
exceptions.

ChrisA



More information about the Python-list mailing list