Details on exceptions

John Roth newsgroups at jhrothjr.com
Thu Nov 20 22:19:48 EST 2003


"Derek Fountain" <nomail at hursley.ibm.com> wrote in message
news:3fbd7c7c$0$1746$5a62ac22 at freenews.iinet.net.au...
> > Library Reference, Built-in Exceptions will tell you
> > everything you want to know.
>
> Ah ha! Yes, it did, thanks. The business of learning Python seems to
revolve
> around learning where, in all the documentation, the thing you're looking
> for is written.
>
> Here's an example: in that page it says: "When exceptions of this type are
> created with a 2-tuple...". Er, what does that mean? I found an example
> which does this:
>
> except IOError, (errno, strerror):
>
> which is presumably the syntax referred to. Where, in the docs or the
> O'Reilly book, can I find a description of this syntax? Can I instantiate
> any class in that manner, or is it somehow specific to the exception
> handling in some way?

Actually, that's the back end: except is part of the try: except: syntax,
and the second argument is extracting things from the exception
object.

They were put there originally either by the routine that created the
exception object, or by the raise statement. One thing you may be
missing is that an exception object is no different from any other
object, and the creator can stuff any attributes into it that it wants.

John Roth






More information about the Python-list mailing list