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


Groups > comp.lang.python > #21518

Re: Raise X or Raise X()?

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; ':-)': 0.06; 'whichever': 0.07; 'python': 0.08; 'arguments,': 0.09; 'caller': 0.09; 'exceptions': 0.09; 'from:addr:python': 0.09; 'args"': 0.16; 'both.': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'parentheses': 0.16; 'received:84.92': 0.16; 'received:84.92.122': 0.16; 'received:84.92.122.60': 0.16; 'received:84.93': 0.16; 'received:84.93.230': 0.16; 'reply-to:addr:python-list': 0.16; 'meant': 0.17; 'wrote:': 0.18; 'arguments': 0.18; '(which': 0.19; "haven't": 0.20; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; 'personally,': 0.23; '"this': 0.24; 'preferred': 0.25; 'fact': 0.27; 'raise': 0.28; "i'm": 0.28; 'arguments.': 0.30; 'sun,': 0.30; 'equivalent': 0.31; 'there': 0.33; 'header:User-Agent:1': 0.33; 'too': 0.33; 'received:84': 0.34; 'steven': 0.34; 'purely': 0.34; 'reply-to:addr:python.org': 0.34; 'to:addr:python-list': 0.35; 'finished': 0.35; 'two': 0.36; 'but': 0.37; 'difference': 0.38; 'some': 0.38; 'think': 0.38; 'should': 0.38; "i'd": 0.39; 'to:addr:python.org': 0.40; 'your': 0.61; 'gone': 0.68; 'header :Reply-To:1': 0.70; 'reply-to:no real name:2**0': 0.72; 'fancy.': 0.84
X-CM-Score 0.00
X-CNFS-Analysis v=2.0 cv=ZZifx7pA c=1 sm=1 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=qePWxsfFzlIA:10 a=eIiAuuIXF8wA:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=r5RFgsWEO7obGTNySocA:9 a=wPNLvfGTeEIA:10 a=0nF1XD0wxitMEM03M9B4ZQ==:117
X-AUTH mrabarnett:2500
Date Mon, 12 Mar 2012 02:26:03 +0000
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2
MIME-Version 1.0
To python-list@python.org
Subject Re: Raise X or Raise X()?
References <387014.2537.1331492695725.JavaMail.geo-discussion-forums@pbjv6> <4f5d3c4c$0$29891$c3e8da3$5496439d@news.astraweb.com>
In-Reply-To <4f5d3c4c$0$29891$c3e8da3$5496439d@news.astraweb.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
Reply-To python-list@python.org
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.579.1331519202.3037.python-list@python.org> (permalink)
Lines 23
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1331519202 news.xs4all.nl 6895 [2001:888:2000:d::a6]:41073
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:21518

Show key headers only | 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