Parsing exceptions the pythonic way
Helmut Jarausch
jarausch at skynet.be
Thu May 29 11:10:53 EDT 2003
Hal Wine wrote:
> 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.
>
Just an idea. Most exceptions carry some information which
is delivered if you offer a variable to take it
as
except IOError,ErrorMessage :
print >>>sys.stderr,"an I/O error occurred - reason: ",ErrorMessage
--
Helmut Jarausch
Lehrstuhl fuer Numerische Mathematik
RWTH - Aachen University
D 52056 Aachen, Germany
More information about the Python-list
mailing list