Skip to content

Instantly share code, notes, and snippets.

@tvorogme
Created August 31, 2018 11:26
Show Gist options
  • Save tvorogme/d7652e48ce65caac28ae2a0ab129b83f to your computer and use it in GitHub Desktop.
Save tvorogme/d7652e48ce65caac28ae2a0ab129b83f to your computer and use it in GitHub Desktop.
Python exception into string
try:
from lol import f
f()
except:
exc_type, exc_value, exc_traceback = sys.exc_info()
with io.StringIO() as buf:
traceback.print_exception(exc_type, exc_value, exc_traceback, file=buf)
print(buf.getvalue())