Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!cyclone03.ams2.highwinds-media.com!news.highwinds-media.com!npeersf01.ams.highwinds-media.com!newsfe18.ams2.POSTED!00000000!not-for-mail From: John J Lee Newsgroups: comp.lang.python Subject: Re: List of WindowsError error codes and meanings References: Message-ID: <8762p48eel.fsf@pobox.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:/SvDK0G9fOcjB8M5GVQIuXKUEPs= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Lines: 34 NNTP-Posting-Host: 82.44.73.236 X-Complaints-To: http://netreport.virginmedia.com X-Trace: newsfe18.ams2 1305978394 82.44.73.236 (Sat, 21 May 2011 11:46:34 UTC) NNTP-Posting-Date: Sat, 21 May 2011 11:46:34 UTC Organization: virginmedia.com Date: Sat, 21 May 2011 12:46:26 +0100 Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:5916 Andrew Berg 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