Exception handling wart in Python
David Bolen
db3l at fitlinxx.com
Mon Nov 5 18:33:28 EST 2001
"David Abrahams" <david.abrahams at rcn.com> writes:
> (...) In general it is not so
> important to know exactly which exceptions can be thrown -- you can always
> handle anything with except: (or catch(...) in C++); all that's lost is the
> ability to report errors accurately. That's a loss, but not as serious a
> loss as what you give up when you don't know:
You should still be able to report the cause of the exception
accurately even in the catch-all case. You've got the sys.exc_info()
information to decode and/or print a traceback if you want. Or, you
could use something like:
except Exception, value:
(...)
to get a normal exception instance. Of course, the latter will only
catch class-based exceptions, so you'd still need a raw except: if you
might get string exceptions.
This sort of thing can be very helpful as a last ditch catch-all
exception handler in an application that can print out a nice
traceback to a log or something, and then restart a master loop in an
application to provide at least a restart mechanism in the event of
unanticipated failure.
--
-- David
--
/-----------------------------------------------------------------------\
\ David Bolen \ E-mail: db3l at fitlinxx.com /
| FitLinxx, Inc. \ Phone: (203) 708-5192 |
/ 860 Canal Street, Stamford, CT 06902 \ Fax: (203) 316-5150 \
\-----------------------------------------------------------------------/
More information about the Python-list
mailing list