raising classes

Tim Peters tim.one at comcast.net
Tue Aug 20 03:38:05 CEST 2002


[Paul Rubin]
> Are you saying that
>
>    class foo(Exception): pass
>    ...
>    raise foo
>
> raises foo's class object rather than instantiating foo?
> [etc]

I may have been <wink>, but if so I was wrong:  I was conflating
exception-raising at the C implementation level with exception-raising at
the Python level.  At the Python level, raise class-or-instance always
produces an instance.  Under the covers, the story is different.

> ...
> I guess that's not so terrible; there's just something "more than one way
> to do it"-ish about it.

There are several ways under the covers, but at the Python level there are
only instances of exception classes, and legacy string exceptions.  My
apologies for any confusion I've caused on this point.





More information about the Python-list mailing list