Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder7.xlned.com!newsfeed.xs4all.nl!newsfeed4.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.016 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'finally:': 0.07; 'try:': 0.09; 'cc:addr:python-list': 0.11; 'clears': 0.16; 'default:': 0.16; 'foo()': 0.16; 'sense:': 0.16; 'unexpected': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; 'seems': 0.21; 'example': 0.22; 'cc:addr:python.org': 0.22; '---': 0.24; 'cc:2**0': 0.24; "i've": 0.25; 'subject:/': 0.26; 'header:In- Reply-To:1': 0.27; 'idea': 0.28; 'message-id:@mail.gmail.com': 0.30; 'anyone': 0.31; 'this.': 0.32; 'received:google.com': 0.35; 'done': 0.36; 'sometimes': 0.38; 'does': 0.39; 'bad': 0.39; 'note:': 0.66; 'silently': 0.84; 'subject:try': 0.84; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:cc:content-type; bh=dEs94uXwPFhZkRYz4JCoJtfimvUHSVhc3T4tIKC7X/o=; b=sNbW4m36oWxsOgExd3SsBL/ds3CE0XQSC3qxXvJTICv0wAHWEm/p2/Tw+FnDCcksiw aFWYcbI75rynMaXmIq0e3cZt4VHv2II0Td68ypIzNTs+Mp6LWgS4SL+AIdlDmDupnHhI NUi5DHxeO9IKMUg8KHPniQhf/XgheZyliU7FnX0J2q4D1qBrLX9x5zPbHFAafFgNXrsZ oh2mLccSNJTky4IntCtZJ3fiNB7Xl7Iwlsp5HGYC86GRaM05O8fsvxQSSTehIvtN+ZrN r0WYpnLPrAbL9JR1+vPZJ4Ibun524ollQFyZDuIXpg+GLXg8xmxbM9kYBKaOBdzpArX3 p8iQ== X-Received: by 10.194.57.208 with SMTP id k16mr24490949wjq.51.1402250270570; Sun, 08 Jun 2014 10:57:50 -0700 (PDT) MIME-Version: 1.0 Sender: joshua.landau.ws@gmail.com In-Reply-To: <87lht73mdl.fsf@elektro.pacujo.net> References: <0a89c96d-de62-42ad-be48-6107ce10d215@googlegroups.com> <539396F3.5090508@stoneleaf.us> <87lht73mdl.fsf@elektro.pacujo.net> From: Joshua Landau Date: Sun, 8 Jun 2014 18:57:10 +0100 X-Google-Sender-Auth: Wdt5bYp0gpyIaN_uG2JbQ34RNFE Subject: Re: try/except/finally Cc: python-list 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: 34 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1402250271 news.xs4all.nl 2972 [2001:888:2000:d::a6]:40197 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:72983 On 8 June 2014 08:12, Marko Rauhamaa wrote: > > Does anyone have an example motivating a return from finally? It seems > to me it would always be a bad idea as it silently clears all unexpected > exceptions. In a general sense: try: something_that_can_break() return foo() # before clean_up finally: clean_up() if default: return default() # after clean_up() What's the best replacement? Note: I've never done this. --- I do sometimes use try: return x finally: x += 1 over ret = x x += 1 return ret now-a-days.