[Tutor] subclassing Exceptions

Sheila King sheila@thinkspot.net
Sat, 21 Jul 2001 21:56:51 -0700


On Sat, 21 Jul 2001 20:41:06 -0700 (PDT), Danny Yoo
<dyoo@hkn.eecs.berkeley.edu>  wrote about Re: [Tutor] subclassing
Exceptions:

:On Sat, 21 Jul 2001, Sheila King wrote:
:
:> :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.
:
:No problem.  (Oh, guess what?  I'll be visiting my parents in Northridge
:next week.  Maybe we could meet for coffee then.  It would be pretty neat
:to say hi in person, no?  *grin*)

Sounds like an idea. I will e-mail you about it.

:> Should I just forego downloading the Python C source?
:
:The source code is useful, but you probably don't need to download it in
:its entirety.  If there's a particular C source file that you're
:interested in, you can use the SourceForge system to browse it:
:
:   http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/python/dist/src/

Great pointer/URL. I've been looking over the C source for exceptions.c.
I can make out quite a bit of what is going on, and I see that it is
apparently calling methods defined in Python.h, which I don't think I'll
snatch right now.

But, it appears to me, that for all exceptions, there are basically:

3 methods (unless you write additional ones?):

__init__
__str__
__getitem__

and 1 data member:

__doc__

Does that sound about right? I know what __init__, __str__ and __doc__
are for. I guess I need to look up the __getitem__ method.

Now, to study the Python source examples you pointed out previously...

Oh, one additional question:

Suppose one were defining a new class. Could you conceive of any
situation where one might want to create an exception that is a data
member of that class??

OK, well what I'm doing, is writing a class that I want to make some
exceptions for. I can't envision these exceptions ever being used
outside of this class. Should they be data members of the class? (I'm
thinking...not?) Maybe I should just define them in the same file as the
class, but not bound to the class.

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