raising classes

Aahz aahz at pythoncraft.com
Mon Aug 19 23:32:36 CEST 2002

In article <mailman.1029774509.27563.python-list at python.org>,
Tim Peters  <tim.one at comcast.net> wrote:
>> Before I add to the current high volume on python-dev, does anyone know
>> why the exception mechanism uses class objects rather than class
>> instances.  In other words, why don't we do
>>     raise Exception()
>You can if you want to (try it!).  I expect some people don't just
>because it's more typing, while others don't because instantiating an
>instance of a class is more expensive than merely using the (already
>full constructed) class object itself.

The latter is what I would have guessed.  Which brings me to my real

Obviously *something* must be instantiated on a per-exception basis.
What kind of object is it?  There was a recent thread on python-dev that
mentioned lazy instantiation of exceptions at the C level; does that
apply to for loops? That is, with the following code, does an actual
exception object get created?

    def f():
        yield 1
        raise StopIteration

    for i in f():
        print i
Aahz (aahz at pythoncraft.com)           <*>         http://www.pythoncraft.com/

Project Vote Smart: http://www.vote-smart.org/

More information about the Python-list mailing list