Details on exceptions

Derek Fountain nomail at hursley.ibm.com
Thu Nov 20 23:04:30 EST 2003


> 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.

No, I got the "exception is just an object idea". What I don't understand is
the assignment of a tuple in the except clause. I thought the thing after
the exception name is an optional variable name to assign a reference to
the exception object to. The O'Reilly Nutshell book says "The optional
target is an identifier that names a variable that Python binds to the
exception object just before the exception handler executes". This doesn't
make sense in this case:

except IOError, (errno, strerror):

The target is a tuple of 2 variable names so how can it bind "the exception
object" to them? The documentation for try/except says that "the
exception's parameter is assigned to the target". So what, exactly, is an
"exception's parameter"?





More information about the Python-list mailing list