View original Gist on GitHub
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))