Best Way to Handle All Exceptions

Vilya Harvey vilya.harvey at
Mon Jul 13 19:55:50 CEST 2009

2009/7/13 seldan24 <seldan24 at>:
> Thank you both for your input.  I want to make sure I get started on
> the right track.  For this particular script, I should have included
> that I would take the exception contents, and pass those to the
> logging module.  For this particular script, all exceptions are fatal
> and I would want them to be.  I just wanted a way to catch them and
> log them prior to program termination.

The logging module has a function specifically to handle this case:

    # do something
    logging.exception("Uh oh...")

The exception() method will automatically add details of the exception
to the log message it creates; as per the docs, you should only call
it from within an exception handler.

Hope that helps,


More information about the Python-list mailing list