How to except the unexpected?

Rene Pijlman at
Sat Mar 4 00:10:17 CET 2006

One of the things I dislike about Java is the need to declare exceptions
as part of an interface or class definition. But perhaps Java got this

I've writen an application that uses urllib2, urlparse, robotparser and
some other modules in the battery pack. One day my app failed with an
urllib2.HTTPError. So I catch that. But then I get a urllib2.URLError, so
I catch that too. The next day, it encounters a urllib2.HTTPError, then a
IOError, a socket.timeout, httplib.InvalidURL,...

How do you program robustly with these modules throwing all those
different (and sometimes undocumented) exceptions at you?

A catchall seems like a bad idea, since it also catches AttributeErrors
and other bugs in the program.

René Pijlman

More information about the Python-list mailing list