raise Exception Syntax question

Peter Hansen peter at engcorp.com
Fri Apr 9 22:36:08 EDT 2004


chris wrote:

>  >>> raise e, "MESSAGE"
> Traceback (most recent call last):
>   File "<interactive input>", line 1, in ?
> Exception: MESSAGE
> 
> 
>  >>> raise e("MESSAGE")
> Traceback (most recent call last):
>   File "<interactive input>", line 1, in ?
> Exception: MESSAGE
> 
> is there a preferable way?

The latter is preferred by many, but in any case note that the
former is basically translated to the latter by Python itself
when it executes that code so you might as well go with it.
The "except" statement catches an instance, after all, so
explicitly raising one is probably a Good Thing.

-Peter



More information about the Python-list mailing list