Path: csiph.com!usenet.pasdenom.info!news.redatomik.org!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'python,': 0.02; 'say,': 0.05; 'expected.': 0.09; 'python': 0.11; '>on': 0.16; '>to': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'iterable:': 0.16; 'iteration': 0.16; 'iteration,': 0.16; 'iteration.': 0.16; 'message- id:@cskk.homeip.net': 0.16; 'ought': 0.16; 'really?': 0.16; 'simpson': 0.16; 'throw': 0.16; 'tuple': 0.16; 'tuple.': 0.16; 'exception': 0.16; 'sat,': 0.16; 'wrote:': 0.18; "python's": 0.19; 'work,': 0.20; 'command': 0.22; 'saying': 0.22; 'shell': 0.22; 'header:User-Agent:1': 0.23; 'instead.': 0.24; 'specify': 0.24; 'cheers,': 0.24; 'source': 0.25; 'this:': 0.26; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; "doesn't": 0.30; "i'm": 0.30; '(which': 0.31; 'code': 0.31; "d'aprano": 0.31; 'exceptions': 0.31; 'steven': 0.31; 'subject:with': 0.35; 'except': 0.35; 'objects': 0.35; 'but': 0.35; 'there': 0.35; 'var': 0.36; 'done': 0.36; 'charset:us- ascii': 0.36; 'possible': 0.36; 'should': 0.36; 'two': 0.37; 'list': 0.37; 'expected': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'expect': 0.39; 'bad': 0.39; 'extremely': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'catch': 0.60; 'dave': 0.60; 'hope': 0.61; "you're": 0.61; 'content-disposition:inline': 0.62; 'importantly,': 0.68; '2015': 0.84; 'bare': 0.84; 'received:192.168.15': 0.84; 'subject:..': 0.84; 'angel': 0.91 Date: Sat, 11 Apr 2015 19:27:27 +1000 From: Cameron Simpson To: python-list@python.org Subject: Re: try..except with empty exceptions MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) References: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20 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: 65 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1428744459 news.xs4all.nl 2927 [2001:888:2000:d::a6]:60921 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:88813 On 10Apr2015 19:38, Rustom Mody wrote: >On Saturday, April 11, 2015 at 7:53:31 AM UTC+5:30, Dave Angel wrote: >> On 04/10/2015 09:42 PM, Steven D'Aprano wrote: >> > On Sat, 11 Apr 2015 05:31 am, sohcahtoa82 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. > >To work, this analogy should also have two python syntaxes like this: > >"Normal" for-loop: >for var in iterable: > suite > >"Empty" for-loop: >for: > suite Well, to throw an anaolgy in the mix, the shell has a bare for syntax. list='a b c' for x in $list do echo $x done echoes a, b and c as you might expect. This: for x do echo $x done echoes the command line arguments. (Which is extremely useful.) But as with Python, the missing iteration means a _default_ source of iteration, not _no_ iteration. To continue the analogy, this: list= for x in $list do echo $x done echoes nothing. As I would hope Steven would expect. Importantly, in both Python and the shell you have a way to specify "nothing". If the empty tuple were to mean "catch everything" then there would not be a way to express "catch nothing". Bad bad bad! Consider this a proof that Python's current meanings for bare except and "except ()" are sensible, using a proof by contradiction. Cheers, Cameron Simpson