Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #5916

Re: List of WindowsError error codes and meanings

From John J Lee <jjl@pobox.com>
Newsgroups comp.lang.python
Subject Re: List of WindowsError error codes and meanings
References <mailman.1847.1305914213.9059.python-list@python.org>
Message-ID <8762p48eel.fsf@pobox.com> (permalink)
Organization virginmedia.com
Date 2011-05-21 12:46 +0100

Show all headers | View raw


Andrew Berg <bahamutzero8825@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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

List of WindowsError error codes and meanings Andrew Berg <bahamutzero8825@gmail.com> - 2011-05-20 12:56 -0500
  Re: List of WindowsError error codes and meanings Genstein <genstein@invalid.invalid> - 2011-05-20 20:47 +0100
    Re: List of WindowsError error codes and meanings Andrew Berg <bahamutzero8825@gmail.com> - 2011-05-20 16:55 -0500
  Re: List of WindowsError error codes and meanings John J Lee <jjl@pobox.com> - 2011-05-21 12:46 +0100
    Re: List of WindowsError error codes and meanings Genstein <genstein@invalid.invalid> - 2011-05-21 16:35 +0100
      Re: List of WindowsError error codes and meanings John Lee <jjl@pobox.com> - 2011-05-22 17:55 +0000
    Re: List of WindowsError error codes and meanings Andrew Berg <bahamutzero8825@gmail.com> - 2011-05-22 09:35 -0500
  Re: List of WindowsError error codes and meanings Thomas Heller <theller@ctypes.org> - 2011-05-26 17:02 +0200
    Re: List of WindowsError error codes and meanings Andrew Berg <bahamutzero8825@gmail.com> - 2011-05-27 04:22 -0500

csiph-web