News for hackers. Stuff that matters.
Re:Postmodern Error Handling in Python 3.6 by mypalmike on Saturday February 25, 2017 @07:56AM (#13731362)
IMO, there's nothing wrong with "except Exception" if your handler is, in fact, meant to handle all exceptions.

(Well, there's one thing wrong, which is that certain standard library errors in Python 2.x don't derive from Exception [socket error, I'm looking at you]. This has been addressed in more recent pythons, but there's still lots of 2.x out there.)

Python's rules for handling exceptions in a class hierarchy are designed to provide programmers with the ability to handle errors at whatever level of granularity makes sense. If your requirements say that the software should treat SSLError and BrokenPipe differently, then by all means, handle them separately.

More often, however, you're making a library call for which any failure has identical requirements. When you're trying to read a configuration file, you probably don't care whether a hard drive is corrupted, has a loose power cable, is on fire, or somehow triggered a divide by zero error somewhere in the bowels of an I/O library.

Re:Postmodern Error Handling in Python 3.6 by jwilk on Saturday February 25, 2017 @09:08AM (#13731633)

  >>> import socket
  >>> issubclass(socket.error, Exception)
  True
It's been like this since Python 2.4 at least.
Re:Postmodern Error Handling in Python 3.6 by mypalmike on Tuesday February 28, 2017 @08:28PM (#13760135)
I stand corrected. Well, partly. Looks like it was changed in 2.6.

https://docs.python.org/2/library/socket.html#socket.error