Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.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: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'subject:Python': 0.06; 'finally:': 0.07; 'except:': 0.09; 'lawrence': 0.09; 'try:': 0.09; 'valueerror:': 0.09; 'variant': 0.09; 'python': 0.11; 'jan': 0.12; 'exception:': 0.16; 'letting': 0.16; 'throw': 0.16; 'unexpected': 0.16; 'url:peps': 0.16; 'valueerror': 0.16; 'exception': 0.16; 'wrote:': 0.18; 'seems': 0.21; '>>>': 0.22; 'error': 0.23; 'url:dev': 0.24; 'changes,': 0.26; 'logging': 0.26; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'raise': 0.29; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; 'bug?': 0.31; 'url:python': 0.33; 'running': 0.33; 'call.': 0.33; 'fri,': 0.33; 'skip:d 20': 0.34; 'could': 0.34; 'problem': 0.35; 'except': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'version': 0.36; 'url:org': 0.36; 'depends': 0.38; 'to:addr:python-list': 0.38; 'rather': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; "you're": 0.61; 'subject:The': 0.64; 'more': 0.64; '30,': 0.65; '2015': 0.84; '2:02': 0.84; 'bare': 0.84; 'surface': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=/oG9LfMVl0AK7/AGDnzoMgvzGPTp8jovbEFuYHnQsak=; b=GWXiCdMSFbagmKt4E7JXckkxiEYHkIXYs5kNDbyEgJM1pwxTUr3C0K2fUBaGGOBgZ+ 4xdJbOJoIqI+/8qSKmakAZG+AI04M5+1Ig8qozg78BtundthCQI00RxZuxT+qG3xINL4 tO5uDMc6AJECH1CXqGMTwP8v06QVWRkVUB+n3UB3by1mxWyp+oL9T/rmSN4wOxQaB/rf lPvyJW3wYyqWg+iTavFd9mpWyw9daE1W6kMJ7kzlRx6b5NbVI4vuNnjGo6BSR2y3Yrp8 rHnembL/TJqtHPFqLLkK0yKld3z+FXbr6BkGtYhAEa+eOoAWlwfPtC7cZNKLAYuYykIf +lDA== X-Received: by 10.66.154.196 with SMTP id vq4mr7420115pab.146.1422609471747; Fri, 30 Jan 2015 01:17:51 -0800 (PST) MIME-Version: 1.0 In-Reply-To: <87r3ucljyv.fsf@elektro.pacujo.net> References: <20150129113238.7eaa986d@bigbox.christie.dr> <87r3uchjyg.fsf@elektro.pacujo.net> <87r3ucljyv.fsf@elektro.pacujo.net> From: Ian Kelly Date: Fri, 30 Jan 2015 02:17:11 -0700 Subject: Re: The Most Diabolical Python Antipattern To: Python Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 46 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1422609481 news.xs4all.nl 2889 [2001:888:2000:d::a6]:52143 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:84872 On Fri, Jan 30, 2015 at 2:02 AM, Marko Rauhamaa wrote: > Mark Lawrence : > >> On 30/01/2015 06:16, Marko Rauhamaa wrote: >>> How about: >>> >>> ============================== >>> try: >>> do_interesting_stuff() >>> except ValueError: >>> try: >>> log_it() >>> except: >>> pass >>> raise >>> ============================== >>> >>> Surprisingly this variant could raise an unexpected exception: >>> >>> ============================== >>> try: >>> do_interesting_stuff() >>> except ValueError: >>> try: >>> log_it() >>> finally: >>> raise >>> ============================== >>> >>> A Python bug? >> >> It depends on the Python version that you're running - I think!!! See >> https://www.python.org/dev/peps/pep-3134/ > > TL;DR > > My Python did do exception chaining, but the problem is the surface > exception changes, which could throw off the whole error recovery. > > So I'm thinking I might have found a valid use case for the "diabolical > antipattern." I suppose, although it seems awfully contrived to me. In any case it would still be better with "except Exception" rather than the bare except. Unless re-raising that ValueError is more important to you than letting the user hit Ctrl-C during the logging call.