Preferred exception style?
Steven Taschuk
staschuk at telusplanet.net
Fri May 30 14:51:49 EDT 2003
Quoth Dave Benjamin:
> 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?
They are, as you suspect, synonymous.
The standard library mostly uses the syntax with a comma. I much
prefer the syntax with parentheses, so much so that I've (just a
moment ago, in fact) submitted a PEP to eliminate the former.
I don't like the former because, in short, it's a holdover from
the days of string exceptions and is ill-suited to instance
exceptions. (The PEP has a more complete account of my reasons;
rather than amplify here, I'll just wait for it to be numbered and
post it in its entirety.)
--
Steven Taschuk staschuk at telusplanet.net
"I tried to be pleasant and accommodating, but my head
began to hurt from his banality." -- _Seven_ (1996)
More information about the Python-list
mailing list