[Tutor] subclassing Exceptions

Sheila King sheila@thinkspot.net
Sat, 21 Jul 2001 19:42:04 -0700


OK, I've become fairly comfortable with defining my own classes and
subclassing other classes and so on...

Now I'm wanting to create some of my own exceptions. I've searched
comp.lang.python at Google Groups, and the archives for this Tutor list,
and faqts.python.com and my copy of Core Python Programming, but all I
find on the subject is essentially this:

"""

You can create a new exception by subclassing one of the standard
exceptions like this:

class MyNewException(SomeStandardException):
    pass


Just use the 'pass' statement unless you want to override some of the
methods/data of the Standard Exception.

"""

And that's all the information I can find.

I tried looking under the /Python20 directory for source or something
for the Exception classes, but can't find it. For example, right now I'm
working on subclassing the rfc822.py module, and I found the file
rfc822.py in /Python20/Lib and studied the source until I understood it,
and could subclass it. I'd like to find something similar for the
standard exception classes. I looked in the /include directory and some
others but can't find what I'm needing.

Thanks for any pointers/tips.

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/