hbutils.reflection.exception

Exception and traceback utilities for debugging and error reporting.

This module provides lightweight helpers for printing and capturing full exception tracebacks. It is designed to simplify error logging and diagnostics by exposing two public utilities:

Example:

>>> from hbutils.reflection.exception import print_traceback, str_traceback
>>> try:
...     raise RuntimeError("runtime error")
... except RuntimeError as e:
...     print_traceback(e)
...     text = str_traceback(e)
...     assert "RuntimeError" in text

__all__

hbutils.reflection.exception.__all__ = ['print_traceback', 'str_traceback']

Built-in mutable sequence.

If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified.

str_traceback

hbutils.reflection.exception.str_traceback(err: BaseException) str[source]

Get the full traceback for an exception object as a string.

This function captures the output of print_traceback() into an in-memory buffer and returns it as a string.

Parameters:

err (BaseException) – Exception object to extract traceback from.

Returns:

Full string representation of the traceback.

Return type:

str

Example:

>>> try:
...     raise RuntimeError('runtime error')
... except RuntimeError as e:
...     s = str_traceback(e)
...     print(s)
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
    raise RuntimeError('runtime error')
RuntimeError: runtime error