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


Groups > comp.lang.python > #88797

Re: try..except with empty exceptions

Path csiph.com!usenet.pasdenom.info!news.albasani.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <davea@davea.name>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.007
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'say,': 0.05; 'plenty': 0.07; 'advance': 0.07; 'except:': 0.09; 'expected.': 0.09; 'logic': 0.09; 'specified,': 0.09; 'try:': 0.09; "wouldn't": 0.14; 'clause.': 0.16; 'distinct': 0.16; 'empty,': 0.16; 'ought': 0.16; 'really?': 0.16; 'semantics': 0.16; 'syntax,': 0.16; 'tuple': 0.16; 'tuple.': 0.16; 'exception': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'saying': 0.22; 'header:User-Agent:1': 0.23; 'instead.': 0.24; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; "doesn't": 0.30; 'specified': 0.30; "i'm": 0.30; 'code': 0.31; "d'aprano": 0.31; 'exceptions': 0.31; 'omitted': 0.31; 'steven': 0.31; 'lists': 0.32; 'languages': 0.32; 'could': 0.34; 'problem': 0.35; 'subject:with': 0.35; 'except': 0.35; 'no,': 0.35; 'objects': 0.35; 'next': 0.36; 'possible': 0.36; 'should': 0.36; 'two': 0.37; 'list': 0.37; 'being': 0.38; 'expected': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'anything': 0.39; 'expect': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'catch': 0.60; "you're": 0.61; 'email addr:gmail.com': 0.63; 'different': 0.65; 'charset:windows-1252': 0.65; 'received:74.208': 0.68; '2015': 0.84; 'bare': 0.84; 'collection.': 0.84; 'compare:': 0.84; 'presumably': 0.84; 'subject:..': 0.84
Date Fri, 10 Apr 2015 22:23:14 -0400
From Dave Angel <davea@davea.name>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0
MIME-Version 1.0
To python-list@python.org
Subject Re: try..except with empty exceptions
References <64a75c32-e0ab-4ce0-9373-358c2669fe6e@googlegroups.com> <785010c0-6bcc-46d7-b7e0-0ed062fabbc7@googlegroups.com> <55287c0d$0$13000$c3e8da3$5496439d@news.astraweb.com>
In-Reply-To <55287c0d$0$13000$c3e8da3$5496439d@news.astraweb.com>
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
X-Provags-ID V03:K0:ZGRFk6RLqXM+TyMHmUc2UG69s1euDnalT75Hw5A0da03KiIPHbP LdjcpKwyjD5/fwhc4fiI4C3i4mDH7lDtp7F3TS5X5pVM3Js54SwB7/fRrKLNToieVJV5Dd7 2wSYZUdMqkpr+dGcppPGHP2o5YubNsIZfV/ghJA2lPmqKsFrpG1ADWj/xQYPsOu4U42g5Zw ikUrBJJu2qgkY0M1Hx1jg==
X-UI-Out-Filterresults notjunk:1;
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.211.1428718999.12925.python-list@python.org> (permalink)
Lines 48
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1428718999 news.xs4all.nl 2898 [2001:888:2000:d::a6]:35265
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:88797

Show key headers only | View raw


On 04/10/2015 09:42 PM, Steven D'Aprano wrote:
> On Sat, 11 Apr 2015 05:31 am, sohcahtoa82@gmail.com wrote:
>
>> It isn't document because it is expected.  Why would the exception get
>> caught if you're not writing code to catch it?  If you write a function
>> and pass it a tuple of exceptions to catch, I'm not sure why you would
>> expect it to catch an exception not in the tuple.  Just because the tuple
>> is empty doesn't mean that it should catch *everything* instead.  That
>> would be counter-intuitive.
>
> Really? I have to say, I expected it.
>
>

I'm astounded at your expectation.  That's like saying a for loop on an 
empty list ought to loop on all possible objects in the universe.

The tuple lists those exceptions you're interested in, and they are 
tried, presumably in order, from that collection.  If none of those 
match, then the logic will advance to the next except clause.  If the 
tuple is empty, then clearly none will match.

> try:
>      spam()
> except This, That:
>      # Implicitly a tuple of two exceptions.
>      pass
>
>
> Compare:
>
> try:
>      spam()
> except:
>      # Implicitly an empty tuple.

No, an omitted item is not the same as an empty tuple.  If it were, then 
we wouldn't have the problem of bare excepts, which are so tempting to 
novices.  There's plenty of precedent in many languages for a missing 
item being distinct from anything one could actually supply.

When there's no tuple specified, it's a different syntax, and the 
semantics are specified separately.



-- 
DaveA

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


Thread

try..except with empty exceptions Pavel S <pavel@schon.cz> - 2015-04-10 01:48 -0700
  Re: try..except with empty exceptions Chris Angelico <rosuav@gmail.com> - 2015-04-10 18:58 +1000
  Re: try..except with empty exceptions sohcahtoa82@gmail.com - 2015-04-10 12:31 -0700
    Re: try..except with empty exceptions Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-04-11 11:42 +1000
      Re: try..except with empty exceptions Dave Angel <davea@davea.name> - 2015-04-10 22:23 -0400
        Re: try..except with empty exceptions Rustom Mody <rustompmody@gmail.com> - 2015-04-10 19:38 -0700
          Re: try..except with empty exceptions Dave Angel <davea@davea.name> - 2015-04-10 23:46 -0400
            Re: try..except with empty exceptions Rustom Mody <rustompmody@gmail.com> - 2015-04-10 21:17 -0700
              Re: try..except with empty exceptions Rustom Mody <rustompmody@gmail.com> - 2015-04-10 21:39 -0700
          Re: try..except with empty exceptions Cameron Simpson <cs@zip.com.au> - 2015-04-11 19:27 +1000
            Re: try..except with empty exceptions Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-04-11 21:00 +1000
              Re: try..except with empty exceptions Chris Angelico <rosuav@gmail.com> - 2015-04-11 21:21 +1000
              Re: try..except with empty exceptions Ian Kelly <ian.g.kelly@gmail.com> - 2015-04-11 12:49 -0600
              Re: try..except with empty exceptions Chris Angelico <rosuav@gmail.com> - 2015-04-12 06:04 +1000
              Re: try..except with empty exceptions Chris Angelico <rosuav@gmail.com> - 2015-04-12 06:05 +1000
        Re: try..except with empty exceptions Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-04-11 17:11 +1000
          Re: try..except with empty exceptions Serhiy Storchaka <storchaka@gmail.com> - 2015-04-11 11:22 +0300
            Re: try..except with empty exceptions Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-04-11 20:47 +1000
          Re: try..except with empty exceptions Dave Angel <davea@davea.name> - 2015-04-11 06:14 -0400
          Re: try..except with empty exceptions Dave Angel <davea@davea.name> - 2015-04-11 06:24 -0400
          Re: try..except with empty exceptions Ian Foote <ian@feete.org> - 2015-04-11 15:20 +0100
      Re: try..except with empty exceptions Terry Reedy <tjreedy@udel.edu> - 2015-04-11 04:58 -0400
  Re: try..except with empty exceptions Dave Angel <davea@davea.name> - 2015-04-10 16:27 -0400
  Re: try..except with empty exceptions Rustom Mody <rustompmody@gmail.com> - 2015-04-10 18:56 -0700

csiph-web