Testing and Diagnostics Modules
traceback
Extracts and formats stack frames and exception information without requiring immediate printing. TracebackException can represent an exception for later formatting without retaining the original frame objects. Captured local values can expose secrets; leave capture_locals disabled unless necessary. In Python 3.13, exc_type_str replaces the deprecated exc_type attribute.
Formal Syntax & Structure
python syntaxpython
import tracebackReturn Value
module
Module namespace available through import; import is a statement, not a value-returning expression.
Working Example
Example Snippetpython
import tracebacktry: int("tea")except ValueError as error: summary = traceback.TracebackException.from_exception(error) print(summary.exc_type_str)