[Tutor] subclassing Exceptions
Sheila King
sheila@thinkspot.net
Sat, 21 Jul 2001 20:30:38 -0700
On Sat, 21 Jul 2001 20:21:34 -0700 (PDT), Danny Yoo
<dyoo@hkn.eecs.berkeley.edu> wrote about Re: [Tutor] subclassing
Exceptions:
:There's a list of standard Python exceptions here:
:
: http://python.org/doc/current/lib/module-exceptions.html
Right, seen that many a time, plus also in Core Python Programming as
well...
:As to where they're defined... hmmm... I need to check... ah! They are
:very deeply embedded into Python's internal definition --- they aren't in
:a particular Python file. If you're curious, you can take a look at the:
:
: Python/exceptions.c
:
:file in the Python source code. I don't think that it will help, though,
:in understanding how to subclass exceptions for your own use: it's in C.
Ah, source code...that doesn't come with the standard Windows install
.exe version, does it? (It does come with the Unix installs, I'm sure.)
I probably would have to go to python.org and grab it.
Do you think it would be that difficult for me to understand the C code?
(I have taught C++ for the past two years to AP Comp Sci
students...granted, an Intro level College course...not overly
in-depth.)
:Instead, it's probably better to look at specific examples of subclassed
:exceptions in the Python standard library. For example, we can take a look
:at the XML processing library, 'xml.sax',
:
: http://python.org/doc/current/lib/module-xml.sax.html
:
:which has a definition of a 'SAXException' in the xml/sax/_exceptions.py
:library file:
[code and comments snipped]
:somewhere within our exception subclass. We can see a simpler example in
:ConfigParser.py, which also defines its own "Error" exception class:
[code snipped]
:Take a look at the library, and see how it defines and uses subclasses
:exceptions. If you have questions, feel free to ask. Good luck!
Thanks heaps for these pointers, Danny. I will look the examples over
and ask if I have questions.
Should I just forego downloading the Python C source?
--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/