Python:traceback
lastmod 2026-11-10created 2020-08-052 edits
traceback is a Python standard library module that extracts, formats, and prints stack trace information for exceptions. Using print_exc and format_exc, you can print the current exception or get it as a string in the same format the interpreter shows for unhandled exceptions, and even when there is no exception, print_stack prints the current call stack. It is used to catch exceptions and log them, or to check the call path while debugging.