Traceback2

1.4.0 · maintenance · verified Sat Apr 11

Traceback2 is a Python library that provides a backport of the standard library's `traceback` module to older supported Python versions. Its primary goal was to offer modern traceback formatting and functionality to environments where the native `traceback` module lacked these features. The current version is 1.4.0, released in March 2015, indicating a very slow release cadence and minimal, if any, active development for new features or modern Python versions.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import `traceback2` and use its `print_exc` function within an exception handler to print the current exception's traceback. It is typically aliased as `traceback` to match the standard library module it backports.

import traceback2 as traceback

def problematic_function():
    raise ValueError("Something went wrong in the function!")

try:
    problematic_function()
except ValueError as e:
    print(f"Caught an exception: {e}")
    print("\n--- Traceback (formatted by traceback2) ---")
    traceback.print_exc()

view raw JSON →