Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!selfless.tophat.at!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'franklin': 0.07; 'raised': 0.07; 'received:edu.au': 0.07; 'callable': 0.09; 'exception.': 0.09; 'it;': 0.09; 'module)': 0.09; 'scientists': 0.09; 'pm,': 0.10; 'exception': 0.12; 'wrote:': 0.14; "'hello": 0.16; 'balloon': 0.16; 'cc:name:python list': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'function;': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'received:202.125.174': 0.16; 'received:202.125.174.133': 0.16; 'received:boardofstudies.nsw.edu.au': 0.16; 'received:cskk.homeip.net': 0.16; 'received:harvey.boardofstudies.nsw.edu.au': 0.16; 'received:homeip.net': 0.16; 'received:nsw.edu.au': 0.16; 'reraise': 0.16; 'trace.': 0.16; 'stack': 0.16; 'cc:addr:python- list': 0.17; 'tue,': 0.17; 'trace': 0.19; 'cheers,': 0.19; 'header :In-Reply-To:1': 0.21; 'cc:2**0': 0.22; 'referring': 0.23; 'runs': 0.23; 'code': 0.24; 'function': 0.25; 'later': 0.26; 'raise': 0.28; 'subject:?': 0.29; 'facility': 0.29; 'cc:addr:python.org': 0.30; 'worker': 0.30; 'it.': 0.31; 'print': 0.31; 'anyone': 0.32; "i've": 0.33; '...': 0.34; 'nobody': 0.34; 'header:User-Agent:1': 0.35; 'try:': 0.35; 'logs': 0.36; 'subject:/': 0.36; 'charset:us- ascii': 0.36; 'received:au': 0.37; 'thread': 0.37; 'put': 0.37; 'think': 0.38; 'subject:: ': 0.38; "i'd": 0.39; 'returned': 0.39; 'simply': 0.60; 'john': 0.62; 'dangerous': 0.65; 'received:202': 0.66; 'attention': 0.67; '"what': 0.67; 'loose': 0.67; 'cameron': 0.73; 'spoke': 0.73; 'catches': 0.84; 'exc:': 0.84; 'paris,': 0.84; 'subject:try': 0.84; 'ask,': 0.91 Date: Sat, 21 May 2011 15:40:20 +1000 From: Cameron Simpson To: James Mills Subject: Re: Overuse of try/except/else? MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) References: Cc: python list 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: 34 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1305956425 news.xs4all.nl 49180 [::ffff:82.94.164.166]:36437 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:5902 On 11May2011 13:37, James Mills wrote: | On Tue, May 10, 2011 at 7:34 PM, Jean-Michel Pichavant | wrote: | > You can reraise the exception without loosing the stack trace. | > | > try: | > ... | > except SomeException, exc: | > log(exc) | > print 'Hello world' | > raise # "raise exc" would loose the original stack trace | | Valid point :) However I was referring to real experience | where I've seen code that "catches all any any exception" | and simply logs it. I've put code like that in a worker thread occasionally, because there's nobody "outside" to catch it; the submitter's attention is elsewhere. These days I think I'd use a LateFunction (a facility of my own which is a lot like the futures module) which returns a callable when you submit a function; the worker thread runs the submitted function and catches the return value or raised exception. Anyone who calls the returned callable later gets the return value or the exception reraised as appropriate, so one can avoid the dangerous "catch everything and log" scenario. Cheers, -- Cameron Simpson DoD#743 http://www.cskk.ezoshosting.com/cs/ Observing the first balloon ascent in Paris, [Ben] Franklin heard a scoffer ask, "What good is it?" He spoke for a generation of scientists in his retort, "What good is a newly born infant?" - John F. Kasson