[Python-ideas] PEP 3151 - Reworking the OS and IO exception hierarchy (again)

Antoine Pitrou solipsis at pitrou.net
Thu Nov 11 17:40:28 CET 2010

On Thu, 11 Nov 2010 17:01:00 +0100
Georg Brandl <g.brandl at gmx.net> wrote:
> And as Antoine already showed, whether a given code that does I/O raises
> IOError or OSError is pretty much arbitrary.  I agree for socket.error
> though; there needs to be a catch-all way to intercept network exceptions.

I can understand the desire to intercept network exceptions to print
out messages.

However, socket.error can also indicate a programming error: for
example, trying to read from an unconnected socket. So, having a
catch-all for socket.error can hide bugs in the code. The real way to
discriminate errors is by using errno, not the module raising the
error. That's why the PEP proposes errno-specific classes such as

Besides, useful feedback for the user requires printing the error
message (which is filled out by the OS and doesn't depend on Python's
exception hierarchy), and preferably which network service failed
responding; just printing "network error" is completely unhelpful.



More information about the Python-ideas mailing list