Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #21518

Re: Raise X or Raise X()?

Date 2012-03-12 02:26 +0000
From MRAB <python@mrabarnett.plus.com>
Subject Re: Raise X or Raise X()?
References <387014.2537.1331492695725.JavaMail.geo-discussion-forums@pbjv6> <4f5d3c4c$0$29891$c3e8da3$5496439d@news.astraweb.com>
Newsgroups comp.lang.python
Message-ID <mailman.579.1331519202.3037.python-list@python.org> (permalink)

Show all headers | View raw


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". :-)

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Raise X or Raise X()? bvdp <bob@mellowood.ca> - 2012-03-11 12:04 -0700
  Re: Raise X or Raise X()? Irmen de Jong <irmen.NOSPAM@xs4all.nl> - 2012-03-11 21:37 +0100
    Re: Raise X or Raise X()? Chris Rebert <clp2@rebertia.com> - 2012-03-11 14:49 -0700
    Re: Raise X or Raise X()? Stefan Behnel <stefan_ml@behnel.de> - 2012-03-12 14:52 +0100
      Re: Raise X or Raise X()? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-03-12 15:08 +0000
        Re: Raise X or Raise X()? Stefan Behnel <stefan_ml@behnel.de> - 2012-03-12 17:08 +0100
  Re: Raise X or Raise X()? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-03-11 23:59 +0000
    Re: Raise X or Raise X()? bvdp <bob@mellowood.ca> - 2012-03-11 18:53 -0700
    Re: Raise X or Raise X()? MRAB <python@mrabarnett.plus.com> - 2012-03-12 02:26 +0000
  Re: Raise X or Raise X()? Jean-Michel Pichavant <jeanmichel@sequans.com> - 2012-03-12 11:37 +0100
  Re: Raise X or Raise X()? Robert Kern <robert.kern@gmail.com> - 2012-03-12 12:47 +0000
  Re: Raise X or Raise X()? James Elford <fil.oracle@gmail.com> - 2012-03-12 13:06 +0000
  Re: Raise X or Raise X()? Chris Angelico <rosuav@gmail.com> - 2012-03-13 00:13 +1100

csiph-web