On 11/03/2012 23:59, Steven D'Aprano wrote:
On Sun, 11 Mar 2012 12:04:55 -0700, bvdp wrote:

 Which is preferred in a raise: X or X()?

Both.

Always use raise "X(*args)" when you need to provide arguments (which you
should always do for exceptions meant for the caller to see). The form
"raise X, args" should be considered discouraged, and in fact is gone in
Python 3.x.

Purely internal exceptions (which you raise and catch yourself) don't
need arguments, so there is no difference between the two forms:
"raise X" is exactly equivalent to "raise X()" with no arguments. Use
whichever takes your fancy.

Personally, I used "raise X" to mean "this doesn't need arguments and
should never have any" and "raise X()" to mean "this needs arguments but
I'm too lazy to provide them right now". Think of it as a FIXME.

As some do need arguments, I'd do the opposite; no parentheses would
mean "I haven't finished yet". :-)
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to