Catching very specific exceptions
aleax at mail.comcast.net
Sun Jan 22 17:50:23 CET 2006
Harlin Seritt <harlinseritt at yahoo.com> wrote:
> except socket.error:
> code goes here...
> Of course, though, these are two separate error messages under the same
> error handler though. I've tried:
> except socket.error, (10061, 'Connection refused'):
> except (socket.error, 10061, 'Connection refused'):
> to no avail. What do I need to do to catch each one specifically?
what I've done in such situations is
except socket.error, e:
if e.errno == 10061:
elif e.errno == 10060:
Not sure the code in a socket.error has attributename 'errno', but I
hope you get the general idea.
More information about the Python-list