Raising objects

Michael Chermside mcherm at mcherm.com
Thu May 1 14:15:10 EDT 2003


Alex writes:
> I would explain my desiderata differently: raising any instance
> of NewException raises it; raising any subclass of NewException
> instantiates it (optionally with the provided argument[s]) and
> raises the resulting instance.

Hmm... I'd agree with this EXCEPT that there's currently an
advantage to raising classes instead of instances: the interpreter
may behave AS IF the instance were created and thrown, but
(if I understand the behavior correctly) it doesn't actually
create the object.

Not that performance is the the be-all and end-all of design, nor
is exception handling the most important place to optimize, but
it's kinda neat that it saves this unnecessary object creation
JUST SO LONG AS it goes ahead and creates the object if you ever
do anything which would access that object.

Being able to raise the instance itself is important... then you
can DO things to that instance (eg: create it with certain
settings, then add a few attributes in handlers that re-raise it
as you go up the call stack).

Or-should-that-be-"down"-the-call-stack,-I-can-never-remember

-- Michael Chermside






More information about the Python-list mailing list