« Back to Index

Python Exception Stack Trace Debugging

View original Gist on GitHub

Python Exception Stack Trace Debugging.py

import traceback

try:
    raise ValueError
except:
    tb = traceback.format_exc()
else:
    tb = "No error"
finally:
    print tb

# log the stack
stack = ''.join(traceback.format_exception(exc_cls, exc_val, exc_traceback))