Raise X or Raise X()?
steve+comp.lang.python at pearwood.info
Mon Mar 12 00:59:09 CET 2012
On Sun, 11 Mar 2012 12:04:55 -0700, bvdp wrote:
> Which is preferred in a raise: X or X()?
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
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.
More information about the Python-list