Created
August 31, 2018 11:26
-
-
Save tvorogme/d7652e48ce65caac28ae2a0ab129b83f to your computer and use it in GitHub Desktop.
Python exception into string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://docs.python.org/3/library/traceback.html
https://stackoverflow.com/questions/1218933/can-i-redirect-the-stdout-in-python-into-some-sort-of-string-buffer