hbutils.reflection.exception
- Overview:
This module provides utility functions for handling exceptions and traceback objects. It includes functions to print and retrieve full backtrace information from exception objects, which is useful for debugging and error logging purposes.
print_traceback
- hbutils.reflection.exception.print_traceback(err: BaseException, file=None)[source]
Print full backtrace for exception object.
- Parameters:
err (BaseException) – Exception object to print traceback for.
file (file-like object, optional) – Output file stream. If None, defaults to stdout.
- Example::
>>> try: ... raise RuntimeError('runtime error') ... except RuntimeError as e: ... print_traceback(e) Traceback (most recent call last): File "<stdin>", line 2, in <module> raise RuntimeError('runtime error') RuntimeError: runtime error
Note
See
str_traceback()for getting traceback as a string instead of printing.
str_traceback
- hbutils.reflection.exception.str_traceback(err: BaseException) str[source]
Get full backtrace for exception object as a string.
- Parameters:
err (BaseException) – Exception object to extract traceback from.
- Returns:
Full string representation of the backtrace.
- 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