raising classes
Thomas Heller
theller at python.net
Mon Aug 19 10:48:05 EDT 2002
"Aahz" <aahz at pythoncraft.com> wrote in message news:ajqun3$8af$1 at panix1.panix.com...
> 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()
> --
(Unneeded) backward compatibility with string exceptions, it seems. See http://www.python.org/doc/essays/stdexceptions.html
Short excerpt:
"""
The raise statement has been extended to allow raising a class exception without explicit instantiation. The following forms, called
the "compatibility forms" of the raise statement, are allowed:
raise exception
raise exception, argument
raise exception, (argument, argument, ...)
When exception is a class, these are equivalent to the following forms:
raise exception()
raise exception(argument)
raise exception(argument, argument, ...)
"""
Thomas
More information about the Python-list
mailing list