Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:error': 0.03; 'causing': 0.04; 'api.': 0.05; 'classes,': 0.05; 'elif': 0.05; 'subject:Python': 0.06; 'notice,': 0.07; 'exception.': 0.09; 'raises': 0.09; 'subject:messages': 0.09; 'throws': 0.09; 'try:': 0.09; 'python': 0.11; ':-(': 0.16; 'e.errno': 0.16; 'errno': 0.16; 'exceptions,': 0.16; 'ioerror': 0.16; 'ioerror,': 0.16; 'open()': 0.16; 'simulate': 0.16; 'subclass': 0.16; 'valueerror': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'module': 0.19; '+0000': 0.22; 'to:name:python-list@python.org': 0.22; 'error': 0.23; 'documented': 0.24; 'received:65.55.116': 0.24; 'mon,': 0.24; 'question': 0.24; "i've": 0.25; 'source': 0.25; 'least': 0.26; 'skip:" 20': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'function': 0.29; 'skip:- 40': 0.29; '[1]': 0.29; 'raise': 0.29; '(like': 0.30; 'errors': 0.30; 'mode': 0.30; 'code': 0.31; 'documenting': 0.31; 'exceptions': 0.31; 'raised': 0.31; 'them?': 0.31; 'file': 0.32; 'there.': 0.32; 'themselves': 0.32; 'says': 0.33; 'url:python': 0.33; 'not.': 0.33; 'actual': 0.34; 'date:': 0.34; "i'd": 0.34; 'except': 0.35; 'something': 0.35; 'but': 0.35; 'there': 0.35; 'version': 0.36; 'raising': 0.36; 'url:org': 0.36; 'operating': 0.37; 'list': 0.37; 'email addr:python.org': 0.37; 'list.': 0.37; 'expected': 0.38; 'sometimes': 0.38; 'url:library': 0.38; 'version,': 0.38; 'to:addr:python-list': 0.38; 'subject:': 0.39; "couldn't": 0.39; '\xa0\xa0\xa0': 0.39; 'to:addr:python.org': 0.39; 'even': 0.60; 'full': 0.61; 'url:3': 0.61; 'course': 0.61; 'information': 0.63; 're:': 0.63; 'more': 0.64; 'email name:python-list': 0.65; 'details': 0.65; 'invalid': 0.68; 'subject': 0.69; 'discover': 0.82; 'find.': 0.84; 'subject:location': 0.84; '\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0': 0.84; 'carlos': 0.91; 'releases.': 0.91; '2013': 0.98 X-TMN: [vwFy6CDcyHCLc+rKI4NbGYVCF1QAPnf+] X-Originating-Email: [carlosnepomuceno@outlook.com] From: Carlos Nepomuceno To: "python-list@python.org" Subject: RE: Python error codes and messages location Date: Mon, 27 May 2013 04:49:28 +0300 Importance: Normal In-Reply-To: <51a2ae95$0$30002$c3e8da3$5496439d@news.astraweb.com> References: , <51a2ae95$0$30002$c3e8da3$5496439d@news.astraweb.com> Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginalArrivalTime: 27 May 2013 01:49:28.0440 (UTC) FILETIME=[6C93E780:01CE5A7C] X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 86 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1369619377 news.xs4all.nl 15883 [2001:888:2000:d::a6]:51122 X-Complaints-To: abuse@xs4all.nl Path: csiph.com!usenet.pasdenom.info!news.stben.net!border3.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Xref: csiph.com comp.lang.python:46153 ----------------------------------------=0A= > From: steve+comp.lang.python@pearwood.info=0A= > Subject: Re: Python error codes and messages location=0A= > Date: Mon=2C 27 May 2013 00:53:41 +0000=0A= > To: python-list@python.org=0A= >=0A= > On Mon=2C 27 May 2013 02:13:54 +0300=2C Carlos Nepomuceno wrote:=0A= >=0A= >> Where can I find all error codes and messages that Python throws (actual= =0A= >> codes and messages from exceptions raised by stdlib)?=0A= >=0A= > There is no list. It is subject to change from version to version=2C=0A= > including point releases.=0A= >=0A= > Many functions and methods document which exceptions they can be expected= =0A= > to raise=2C or at least the *usual* exceptions=2C but many more do not. A= nd=0A= > the error messages themselves are implementation details and are subject= =0A= > to change without notice=2C even if the exception type is a documented pa= rt=0A= > of the API.=0A= >=0A= > You can see a full list of built-in exception types in the docs:=0A= >=0A= > http://docs.python.org/3/library/exceptions.html=0A= >=0A= > but of course since they are classes=2C they can be subclassed=2C and in= =0A= > principle a function that raises (say) ValueError might sometimes raise a= =0A= > subclass of ValueError without documenting it.=0A= >=0A= > So the actual answer to your question is:=0A= >=0A= > "Read the source code."=0A= >=0A= >=0A= > Sorry :-(=0A= =0A= That's bad! I'd like to check all the IOError codes that may be raised by a= function/method but the information isn't there.=0A= =0A= Take open() for example[1]. It only says it raises an IOError exception.=0A= =0A= I've had to try "open(''=2C'r')" to discover that Errno 22 is the one "IOEr= ror: [Errno 22] invalid mode ('r') or filename: ''"=0A= =0A= Will I only be able to get all error codes reading the source code of open(= )?=0A= =0A= Is there a way to simulate the errors instead of actually causing them? I m= ean not raising an instance of IOError that I create (like "raise IOError(6= 66=2C'Hell happens')")=2C but one with the actual contents 'args =3D (errno= =2C strerr)' that open() would raise?=0A= =0A= Something like:=0A= =0A= f=3Dopen('filename'=2C'r')=0A= for x in range(25):=0A= =A0=A0=A0 try:=0A= =A0=A0=A0=A0=A0=A0=A0 f.raise_errno(x)=0A= =A0=A0=A0 except IOError=2C e:=0A= =A0=A0=A0=A0=A0=A0=A0 if=A0=A0 e.errno =3D=3D 1:=0A= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 treat_err1()=0A= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 continue=0A= =A0=A0=A0=A0=A0=A0=A0 elif e.errno =3D=3D 2:=0A= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 treat_err2()=0A= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 continue=0A= ...=0A= =0A= =0A= =0A= [1] http://docs.python.org/2/library/functions.html#open=0A= =0A= >> I've already found the module 'errno' and got a dictionary=0A= >> (errno.errorcode) and some system error messages=0A= >> (os.strerror(errno.ENAMETOOLONG)) but there's more I couldn't find.=0A= >=0A= > These are the standard C operating system and file system error codes=2C= =0A= > not Python exceptions.=0A= =0A= Yes=2C the docs say it's from "linux/include/errno.h". =