Parsing exceptions the pythonic way

Hal Wine hal_wine at yahoo.com
Thu May 29 10:13:53 EDT 2003


It seems this should be easier and cleaner than I've figured out, 
so I guess I don't know python very well yet :(

What's the pythonic way to get error numbers or base messages 
from an exception?  Solution need only work for standard library.

For example, urllib.urlopener catches socket errors and raises 
them as IOError. It also raises non-successful HTTP status values 
as IOError.  Of course, the location of any numeric code or 
message is different in each case.

The options I see are:
- do some hack in my except clause
- write my own replication of urllib.urlopener accessing httplib 
directly
- give up on some of my functionality

None of these seem either "pythonic" or elegant. Nor do they 
generalize to other standard library exceptions.

Thanks,
--Hal





More information about the Python-list mailing list