traceback docs
source code
This module provides a standard interface to extract, format and print stack traces of Python programs. It exactly mimics the behavior of the Python interpreter when it prints a stack trace. This is useful when you want to print stack traces under program control, such as in a “wrapper” around the interpreter.
traceback.print_exception(etype, value, tb, limit=None, file=None, chain=True)
Print exception information and stack trace entries from traceback object tb to file. This differs from print_tb() in the following ways:
if tb is not None, it prints a header Traceback (most recent call last):
it prints the exception etype and value after the stack trace
if type(value) is SyntaxError and value has the appropriate format, it prints the line where the syntax error occurred with a caret indicating the approximate position of the error.
The optional limit argument has the same meaning as for print_tb(). If chain is true (the default), then chained exceptions (the cause or context attributes of the exception) will be printed as well, like the interpreter itself does when printing an unhandled exception.
traceback.print_exc(limit=None, file=None, chain=True)
This is a shorthand for print_exception(*sys.exc_info(), limit, file, chain).