Preferred exception style?

Terry Reedy tjreedy at udel.edu
Fri May 30 15:52:24 EDT 2003


"Dave Benjamin" <ramen at lackingtalent.com> wrote in message
news:slrnbdf4a9.b8d.ramen at lackingtalent.com...
> Hey folks,
>
> I was just wondering which style you prefer for raising exceptions.
I never
> really thought about it much, but I was looking at some code today
that said:
>
> raise SomeException, 'some relevant message'
>
> and I tend to do it like this:
>
> raise SomeException('some relevant message')
>
> The two forms seem to have identical results. Any reason to prefer
one over
> the other? Which do you use?

There was a discussion about this a couple of weeks ago.  The first
style is a holdover from when exceptions were strings, and must remain
legal as long as strings remain legal as exceptions.  The second style
only works with exception classes, with the first more-or-less
redefined as a synonym for the second in the as-yet special case when
SomeException is a class.  I learned the first BCE (Before Class
Exceptions).  I intend to use the second in the future.

Terry J. Reedy






More information about the Python-list mailing list