By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,198 Members | 929 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,198 IT Pros & Developers. It's quick & easy.

Handling exceptions consistently with the logging module.

P: n/a
I've just converted my application to use the logging module for its
logging needs (it's quite excellent, actually :)). One thing I still
have to resolve, though: in many places in my application, I want to
catch *all* exceptions *except*, for instance, KeyboardInterrupt and
SystemExit. So I'll have code like this:

try:
callback(data)
except Exception, e:
log.exception("Uncaught exception from callback")
except: # Crazy string exceptions!
log.exception("Uncaught exception from callback")

With my former hand-rolled logging system, those "log.exception" calls
were actually "debug.recoverableException" calls, and if the exception
debug.recoverableException found was in the list of "deadly"
exceptions, it would simply re-raise it.

I've tried that in my logging subclass like so:

def formatException(self, (E, e, tb)):
for exn in deadlyExceptions:
if issubclass(e.__class__, exn):
raise
return cgitb.text((E, e, tb)).rstrip('\r\n')

This, however, doesn't seem to work -- log.exception seems to be
logging (and not re-raising) KeyboardInterrupt, and I have to press
Ctrl-C three times to actually exit my application.

Anyway, I was curious if there's a way to do what I want to do without
modifying every "catch all exceptions" places to catch everything but
the deadly exceptions.

Thanks,
Jeremy
Jul 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.