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: 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 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Sun, Mar 11, 2012 at 1:37 PM, Irmen de Jong wro= te: > 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: >> =C2=A0 for ... >> =C2=A0 =C2=A0 for ... >> =C2=A0 =C2=A0 =C2=A0 for ... >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 if match: >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0raise StopInteration() >> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0else ... >> >> except StopInteration: >> =C2=A0 =C2=A0print "found it" > > "raise X" is a special case of the 3-args raise. Effectively it just rais= es 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-statemen= t 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