Path: csiph.com!x330-a1.tempe.blueboxinc.net!aioe.org!news.stack.nl!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.023 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'jones': 0.09; 'exception': 0.12; 'am,': 0.14; 'wrote:': 0.14; '"don\'t': 0.16; "'hello": 0.16; 'cc:name:python list': 0.16; 'crashes': 0.16; 'defects': 0.16; 'improvement,': 0.16; 'received:192.168.200': 0.16; 'reraise': 0.16; 'trace.': 0.16; 'stack': 0.16; 'trace': 0.19; 'tue,': 0.20; 'cc:2**0': 0.20; 'code': 0.22; 'header:In-Reply- To:1': 0.22; 'cc:addr:python-list': 0.22; 'incorrect': 0.23; 'raise': 0.29; 'error': 0.29; 'subject:?': 0.29; 'cc:addr:python.org': 0.31; 'it.': 0.31; 'determine': 0.31; 'source': 0.32; 'things': 0.33; 'received:192': 0.34; 'rule': 0.35; 'print': 0.35; 'finding': 0.35; 'header:User-Agent:1': 0.35; 'lie': 0.35; 'try:': 0.35; 'subject:/': 0.36; 'received:192.168': 0.37; 'but': 0.38; 'could': 0.39; 'where': 0.39; 'except': 0.39; 'would': 0.40; "it's": 0.40; 'charset:windows-1252': 0.61; '2011': 0.62; 'harder': 0.65; 'loose': 0.68; 'exc:': 0.84; 'constitute': 0.91; 'doesn\x92t': 0.91; 'crash': 0.93 X-IronPort-AV: E=Sophos;i="4.64,345,1301868000"; d="scan'208";a="1669032" X-Virus-Scanned: amavisd-new at zimbra.sequans.com Date: Tue, 10 May 2011 11:34:10 +0200 From: Jean-Michel Pichavant User-Agent: Mozilla-Thunderbird 2.0.0.24 (X11/20100328) MIME-Version: 1.0 To: James Mills Subject: Re: Overuse of try/except/else? References: In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit 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: 1305020059 news.xs4all.nl 41110 [::ffff:82.94.164.166]:44646 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:5061 James Mills wrote: > On Tue, May 10, 2011 at 10:40 AM, Kyle T. Jones > wrote: > >> It has been hard for me to determine what would constitute overuse. >> > > A rule of thumb I always follow and practice is: > > "Let the error lie where it occurred." > > or > > "Don't hide errors.". > > It's good practice to follow IHMO as it makes it easier to find > the source of defects in your function(s). If you constantly > do things like try/except/log then it makes finding the source > harder and may make it harder to identify what caused it. > 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 JM PS : "code that crashes could use improvement, but incorrect code that doesn’t crash is a horrible nightmare." (I don't know the author)