Last active
December 11, 2015 23:35
-
-
Save squito/c385d3ad1932e875c7d7 to your computer and use it in GitHub Desktop.
"chaining" python exception
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
import traceback | |
import sys | |
def a(x): b(x) | |
def b(x): c(x) | |
def c(x): d(x) | |
def d(x): raise Exception("blah %s" % x) | |
try: | |
a(1) | |
except: | |
orig_tb = traceback.format_exception(*sys.exc_info())[1:] | |
raise Exception(''.join(["foo\n", "\tcaused by:\n"] + orig_tb)) | |
## output: | |
Traceback (most recent call last): | |
File "<stdin>", line 9, in <module> | |
Exception: foo | |
caused by: | |
File "<stdin>", line 2, in <module> | |
File "<stdin>", line 1, in a | |
File "<stdin>", line 1, in b | |
File "<stdin>", line 1, in c | |
File "<stdin>", line 1, in d | |
Exception: blah 1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment