List of WindowsError error codes and meanings

John J Lee jjl at pobox.com
Sat May 21 07:46:26 EDT 2011


Andrew Berg <bahamutzero8825 at gmail.com> writes:

> This is probably somewhat off-topic, but where would I find a list of
> what each error code in WindowsError means? WindowsError is so broad
> that it could be difficult to decide what to do in an except clause.
> Fortunately, sys.exc_info()[1][0] holds the specific error code, so I
> could put in an if...elif...else clause inside the except clause if I
> needed to, but I don't know what all the different errors are.

Since Python 2.5, the errno attribute maps the Windows error to error
codes that match the attributes of module errno.

http://docs.python.org/library/exceptions.html#exceptions.WindowsError

So for some purposes you can use the same UNIXy error codes you can use
on most other platforms.  Example:

import errno

try:
    operation()
except WindowsError, exc:
    if exc.errno != errno.ENOENT:
        raise
    print "file/directory does not exist"

Obviously whether this is useful depends on the error cases you need to
handle.

Undocumented: when there's no useful mapping to errno, you get
errno.EINVAL.


John



More information about the Python-list mailing list