Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #5061

Re: Overuse of try/except/else?

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 <prvs=104a5b79d=jeanmichel@sequans.com>
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 <jeanmichel@sequans.com>
User-Agent Mozilla-Thunderbird 2.0.0.24 (X11/20100328)
MIME-Version 1.0
To James Mills <prologic@shortcircuit.net.au>
Subject Re: Overuse of try/except/else?
References <iqa1fd$4l0$1@dont-email.me> <BANLkTi=Gx=3G+QXwVB1Ls205os+cPdCXLA@mail.gmail.com>
In-Reply-To <BANLkTi=Gx=3G+QXwVB1Ls205os+cPdCXLA@mail.gmail.com>
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 8bit
Cc python list <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1376.1305020059.9059.python-list@python.org> (permalink)
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

Show key headers only | View raw


James Mills wrote:
> On Tue, May 10, 2011 at 10:40 AM, Kyle T. Jones
> <onexpadREMOVE@evomeryahoodotyouknow.com> 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)

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Overuse of try/except/else? "Kyle T. Jones" <onexpadREMOVE@EVOMERyahoodotyouknow.com> - 2011-05-09 19:40 -0500
  Re: Overuse of try/except/else? James Mills <prologic@shortcircuit.net.au> - 2011-05-10 11:09 +1000
  Re: Overuse of try/except/else? Jean-Michel Pichavant <jeanmichel@sequans.com> - 2011-05-10 11:34 +0200
  Re: Overuse of try/except/else? Adam Tauno Williams <awilliam@whitemice.org> - 2011-05-10 07:36 -0400
    Re: Overuse of try/except/else? Hans Georg Schaathun <hg@schaathun.net> - 2011-05-10 13:10 +0100
  Re: Overuse of try/except/else? Paul Probert <paulprobert@sbcglobal.net> - 2011-05-10 22:26 -0500
  Re: Overuse of try/except/else? James Mills <prologic@shortcircuit.net.au> - 2011-05-11 13:37 +1000
  Re: Overuse of try/except/else? Daniel Kluev <dan.kluev@gmail.com> - 2011-05-22 00:33 +1100

csiph-web