Zope Exceptions

6.0 · active · verified Thu Apr 16

This package provides general-purpose exception classes and implementations for the Zope ecosystem, designed to extend Python's standard `traceback` module with additional context information. It facilitates annotating tracebacks with `__traceback_info__` for unstructured data or `__traceback_supplement__` for delayed, structured data. It is currently at version 6.0 and receives updates primarily driven by Python version support and significant ecosystem changes, maintaining an active but irregular release cadence.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `__traceback_info__` to inject context into an exception's traceback. The `format_exception` function then processes this enriched information for output, making debugging easier.

import sys
from zope.exceptions import format_exception

def problematic_function(item_id):
    __traceback_info__ = f"Processing item with ID: {item_id}" # Adds context to traceback
    raise ValueError(f"Failed to process item {item_id}")

try:
    problematic_function('XYZ-123')
except Exception:
    exc_type, exc_value, exc_traceback = sys.exc_info()
    formatted_traceback = format_exception(exc_type, exc_value, exc_traceback)
    print("\n".join(formatted_traceback))
    del exc_traceback # Avoid reference cycles

view raw JSON →