Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #21507
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <chris@rebertia.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.038 |
| X-Spam-Evidence | '*H*': 0.92; '*S*': 0.00; 'raises': 0.07; 'python': 0.08; 'exception.': 0.09; 'argument': 0.15; 'both.': 0.16; 'constructed': 0.16; 'eliminated': 0.16; 'permitted.': 0.16; 'raise.': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.18; 'instance': 0.18; 'cheers,': 0.20; 'cc:no real name:2**0': 0.21; 'header:In-Reply-To:1': 0.22; 'though.': 0.23; 'preferred': 0.25; 'cc:2**0': 0.26; 'raise': 0.28; "i'm": 0.28; 'message- id:@mail.gmail.com': 0.29; 'cc:addr:python.org': 0.29; 'pm,': 0.29; 'sun,': 0.30; 'chris': 0.30; 'error': 0.30; 'specified': 0.31; 'cases': 0.32; "i've": 0.32; 'majority': 0.34; 'try:': 0.34; 'however,': 0.35; '...': 0.35; 'list.': 0.35; 'url:python': 0.35; 'received:209.85.214': 0.36; 'question': 0.36; 'received:google.com': 0.37; 'received:209.85': 0.38; 'url:org': 0.39; "i'd": 0.39; 'except': 0.39; 'received:209': 0.39; 'special': 0.66; '11,': 0.68; 'therefore,': 0.68; 'blank': 0.74; 'and:': 0.84; 'it"': 0.84; 'sender:addr:chris': 0.84; 'url:reference': 0.84; 'to:none': 0.93 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:cc:content-type :content-transfer-encoding; bh=0xF4rZE08SOwSZA9FJesERMNGtpbjf4TB4IWICIYQng=; b=J6PRrI+/96UexSZMFyYnhsTJOKwaN78EzGtvr8+lEKUDSwgl2w/pBDCsmVHyQ672dK 97fOkLeMhDI/fD8gG1kNB+C3B3FmrEdCdGAW0T9KE6B0rwpCQ4DrEa2SU5eiTYJHUzXg /joq6WeN4KMkunavW7Qb1N9phzSaxydc5KC+g= |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:cc:content-type :content-transfer-encoding:x-gm-message-state; bh=0xF4rZE08SOwSZA9FJesERMNGtpbjf4TB4IWICIYQng=; b=cqUdU/0x8PcRvtUz4cn3pYiBpqt4co/WDkam59F49oZYxwuLA1sXbdU4NnuAIfQjSB 52ITsM/+CA94u5IsKPVdvwMBWbEDdqRmG3uf/TW3fP2BxiKBq2xldofG78OnZOG6wTw3 CIu04oEuFJFH1yxQ1+R5TdiWDyhZ4QYrXiKI0FnnRVKYHiBglp1af9JnP8lHdD7blMpw KY0EjExnRqnVUcR1WXPTK1l5TfK1riO1rl6xN8pYkltkSWq2tFQAOF/F6opnNx1UoTz6 z4amP5kAN/yhFgzHKdbW6oDvoJhaqQbt5YEDNoEyVnP4siAmyoO6XkHVnDcOJGMVRgQq c/8Q== |
| MIME-Version | 1.0 |
| Sender | chris@rebertia.com |
| In-Reply-To | <4f5d0d06$0$6856$e4fe514c@news2.news.xs4all.nl> |
| References | <387014.2537.1331492695725.JavaMail.geo-discussion-forums@pbjv6> <4f5d0d06$0$6856$e4fe514c@news2.news.xs4all.nl> |
| Date | Sun, 11 Mar 2012 14:49:25 -0700 |
| X-Google-Sender-Auth | fXbqg_N__hnHDTavISkMJSz3EtM |
| Subject | Re: Raise X or Raise X()? |
| From | Chris Rebert <clp2@rebertia.com> |
| Cc | python-list@python.org |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | quoted-printable |
| X-Gm-Message-State | ALoCoQmfDsOdt8sZyiPOLT/UDRfhoRSmP2ywWWKfljycs7QePx8MLM8/eH6DJizbqA3kGkkkur6E |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.12 |
| Precedence | list |
| 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.575.1331502573.3037.python-list@python.org> (permalink) |
| Lines | 39 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1331502573 news.xs4all.nl 6942 [2001:888:2000:d::a6]:39492 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:21507 |
Show key headers only | View raw
On Sun, Mar 11, 2012 at 1:37 PM, Irmen de Jong <irmen.NOSPAM@xs4all.nl> wrote:
> On 11-3-2012 20:04, bvdp wrote:
>> Which is preferred in a raise: X or X()? I've seen both. In my specific case I'm dumping out of a deep loop:
>>
>> try:
>> for ...
>> for ...
>> for ...
>> if match:
>> raise StopInteration()
>> else ...
>>
>> except StopInteration:
>> print "found it"
>
> "raise X" is a special case of the 3-args raise. Effectively it just raises an instance
> of X which is constructed with an empty argument list. Therefore, "raise X()" is
> equivalent, as far as I know.
>
> See http://docs.python.org/reference/simple_stmts.html#the-raise-statement
Note that the 3-argument form of `raise` has been eliminated in Python 3.
However, both:
raise an_exception_instance
and:
raise AnExceptionClass # will have a blank error message
are still permitted.
Interesting stylistic question though. I'd support the X() form for
uniformity with the majority of cases where an error message is
specified for the exception.
Cheers,
Chris
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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