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


Groups > comp.lang.python > #5902 > unrolled thread

Re: Overuse of try/except/else?

Started byCameron Simpson <cs@zip.com.au>
First post2011-05-21 15:40 +1000
Last post2011-05-21 15:40 +1000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Overuse of try/except/else? Cameron Simpson <cs@zip.com.au> - 2011-05-21 15:40 +1000

#5902 — Re: Overuse of try/except/else?

FromCameron Simpson <cs@zip.com.au>
Date2011-05-21 15:40 +1000
SubjectRe: Overuse of try/except/else?
Message-ID<mailman.1873.1305956425.9059.python-list@python.org>
On 11May2011 13:37, James Mills <prologic@shortcircuit.net.au> wrote:
| On Tue, May 10, 2011 at 7:34 PM, Jean-Michel Pichavant
| <jeanmichel@sequans.com> 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 <cs@zip.com.au> 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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web