Working with tracebacks in python

August 7, 2022

# 0
# exc_type, exc_value, exc_traceback = sys.exc_info()
 
# 1
# a = traceback.format_exception(exc_type, exc_value, exc_traceback)[-4]
 
# 2
# traces = traceback.extract_tb(exc_traceback)
 
# 3
# traceback.format_list(traceback.extract_tb(exc_traceback))
 
# 4
# traceback.format_tb(e.__traceback__)
from rich.console import Console
 
console = Console()
console.print_exception(max_frames=3, extra_lines=1, suppress=["fastapi", "starlette"])