Capturing exceptions?

Robert Brewer fumanchu at
Wed Aug 25 19:15:50 CEST 2004

Dfenestr8 wrote:
> What's the easiest way to capture the traceback from an exception, and
> write it to a file? Ideally, I'd like to be able to do something like:
> >try:
> >	main()
> >except:
> >	write the traceback to a file

Have a look at the logging module: Loggers can be a bit
complex at first to set up; read the example in the docs
( and go from there.

The upshot is they lead to extremely simple traceback logging:

except Exception:

This snippet writes the full traceback to the file.


Robert Brewer
Amor Ministries
fumanchu at

More information about the Python-list mailing list