Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #46153
| From | Carlos Nepomuceno <carlosnepomuceno@outlook.com> |
|---|---|
| Subject | RE: Python error codes and messages location |
| Date | 2013-05-27 04:49 +0300 |
| References | <51a2ae95$0$30002$c3e8da3$5496439d@news.astraweb.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.2226.1369619377.3114.python-list@python.org> (permalink) |
----------------------------------------
> From: steve+comp.lang.python@pearwood.info
> Subject: Re: Python error codes and messages location
> Date: Mon, 27 May 2013 00:53:41 +0000
> To: python-list@python.org
>
> On Mon, 27 May 2013 02:13:54 +0300, Carlos Nepomuceno wrote:
>
>> Where can I find all error codes and messages that Python throws (actual
>> codes and messages from exceptions raised by stdlib)?
>
> There is no list. It is subject to change from version to version,
> including point releases.
>
> Many functions and methods document which exceptions they can be expected
> to raise, or at least the *usual* exceptions, but many more do not. And
> the error messages themselves are implementation details and are subject
> to change without notice, even if the exception type is a documented part
> of the API.
>
> You can see a full list of built-in exception types in the docs:
>
> http://docs.python.org/3/library/exceptions.html
>
> but of course since they are classes, they can be subclassed, and in
> principle a function that raises (say) ValueError might sometimes raise a
> subclass of ValueError without documenting it.
>
> So the actual answer to your question is:
>
> "Read the source code."
>
>
> Sorry :-(
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.
Take open() for example[1]. It only says it raises an IOError exception.
I've had to try "open('','r')" to discover that Errno 22 is the one "IOError: [Errno 22] invalid mode ('r') or filename: ''"
Will I only be able to get all error codes reading the source code of open()?
Is there a way to simulate the errors instead of actually causing them? I mean not raising an instance of IOError that I create (like "raise IOError(666,'Hell happens')"), but one with the actual contents 'args = (errno, strerr)' that open() would raise?
Something like:
f=open('filename','r')
for x in range(25):
try:
f.raise_errno(x)
except IOError, e:
if e.errno == 1:
treat_err1()
continue
elif e.errno == 2:
treat_err2()
continue
...
[1] http://docs.python.org/2/library/functions.html#open
>> I've already found the module 'errno' and got a dictionary
>> (errno.errorcode) and some system error messages
>> (os.strerror(errno.ENAMETOOLONG)) but there's more I couldn't find.
>
> These are the standard C operating system and file system error codes,
> not Python exceptions.
Yes, the docs say it's from "linux/include/errno.h".
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Python error codes and messages location Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-27 02:13 +0300
Re: Python error codes and messages location Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-05-27 00:53 +0000
RE: Python error codes and messages location Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-27 04:49 +0300
Re: Python error codes and messages location Cameron Simpson <cs@zip.com.au> - 2013-05-27 12:02 +1000
csiph-web