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


Groups > comp.lang.python > #5061

Re: Overuse of try/except/else?

Date 2011-05-10 11:34 +0200
From Jean-Michel Pichavant <jeanmichel@sequans.com>
Subject Re: Overuse of try/except/else?
References <iqa1fd$4l0$1@dont-email.me> <BANLkTi=Gx=3G+QXwVB1Ls205os+cPdCXLA@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.1376.1305020059.9059.python-list@python.org> (permalink)

Show all headers | 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