[Python-Dev] Exception-handling model

David Abrahams dave@boost-consulting.com
Fri, 9 Aug 2002 11:56:45 -0400

I have always been confused about Python's exception-handling model. I hope
someone can clear up a few questions:

http://www.python.org/dev/doc/devel/ref/exceptions.html#l2h-225 says:

    "When an exception is raised, an object (maybe None) is passed as the
exception's value; this object does not affect the selection of an
exception handler, but is passed to the selected exception handler as
additional information. For class exceptions, this object must be an
instance of the exception class being raised."

But unless I misunderstand the source, Luke, Python itself raises
exceptions all over the place with PyErr_SetString(), which uses a class as
the exception type and a string as the exception object. Other uses of
PyErr_SetObject() that I've found /never/ seem to use an instance of the
exception class as the exception object.

If I got that right, what's the meaning of the documentation I quoted?
What rules must one actually follow when raising an exception?


           David Abrahams * Boost Consulting
dave@boost-consulting.com * http://www.boost-consulting.com