Raising objects
Aahz
aahz at pythoncraft.com
Thu May 1 15:09:15 EDT 2003
In article <iZ6sa.46825$K35.1342758 at news2.tin.it>,
Alex Martelli <aleax at aleax.it> wrote:
>
>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.
>
>So, the exception that is propagating is ALWAYS an instance of
>NewException. An except clause catches an exception E, if and
>only if it names a type of which E is an instance.
Note that aside from string exceptions, this is pretty close to the way
it already works:
class C(Exception):
pass
print type(C)
print type(C())
try:
raise C
except C, e:
# e is an instance even though we raised the class
print type(e)
This is another reason why new-style classes can't be accepted yet:
there's no reliable way to tell the distinction between class and
instance.
(I'm sure Alex already knows this; I'm just commenting for the sake of
people reading along.)
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
"In many ways, it's a dull language, borrowing solid old concepts from
many other languages & styles: boring syntax, unsurprising semantics,
few automatic coercions, etc etc. But that's one of the things I like
about it." --Tim Peters on Python, 16 Sep 93
More information about the Python-list
mailing list