How do I find what kind of exception is thrown.
On 05Sep2017 10:50, Antoon Pardon <antoon.pardon at vub.be> wrote:
>Python 2.6.4 on a solaris box.
>I have a program in which all kind of excptions can be thrown and caugth.
>The main program is something like below:
> log unexpected trouble
>Now I found the following in the logs: [Errno 131] Connection reset by peer
>This is a problem I would like to catch earlier however I have no idea what
>exception I would have to catch in order to treat this case.
Almost anything which says "Errno ..." is almost always an OSError (or an
IOError as I found the other day). I try to be quite picky about these. So for
fp = open(filename)
except OSError as e:
if e.errno == errno.ENOENT:
# file missing
... act as if the file were empty ...
# other badness - let the exception escape
Cameron Simpson <cs at cskk.id.au> (formerly cs at zip.com.au)