diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2013-01-09 10:24:48 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2013-01-09 10:24:48 (GMT) |
commit | 7131749959e674ae347e34efabdc6291b21cbe43 (patch) | |
tree | 1e4d4fefa28db3001c4a9f455ff88957d1595aef /Lib/idlelib/run.py | |
parent | 369a7822d68b6b3949587127565e693acc8e7277 (diff) | |
parent | 78470b4c3a423fb304438be269afbbdd2247d676 (diff) | |
download | cpython-7131749959e674ae347e34efabdc6291b21cbe43.zip cpython-7131749959e674ae347e34efabdc6291b21cbe43.tar.gz cpython-7131749959e674ae347e34efabdc6291b21cbe43.tar.bz2 |
Issue #16491: IDLE now prints chained exception tracebacks.
Diffstat (limited to 'Lib/idlelib/run.py')
-rw-r--r-- | Lib/idlelib/run.py | 37 |
1 files changed, 28 insertions, 9 deletions
diff --git a/Lib/idlelib/run.py b/Lib/idlelib/run.py index 9872af4..dbf046b 100644 --- a/Lib/idlelib/run.py +++ b/Lib/idlelib/run.py @@ -171,15 +171,34 @@ def print_exception(): efile = sys.stderr typ, val, tb = excinfo = sys.exc_info() sys.last_type, sys.last_value, sys.last_traceback = excinfo - tbe = traceback.extract_tb(tb) - print('Traceback (most recent call last):', file=efile) - exclude = ("run.py", "rpc.py", "threading.py", "queue.py", - "RemoteDebugger.py", "bdb.py") - cleanup_traceback(tbe, exclude) - traceback.print_list(tbe, file=efile) - lines = traceback.format_exception_only(typ, val) - for line in lines: - print(line, end='', file=efile) + seen = set() + + def print_exc(typ, exc, tb): + seen.add(exc) + context = exc.__context__ + cause = exc.__cause__ + if cause is not None and cause not in seen: + print_exc(type(cause), cause, cause.__traceback__) + print("\nThe above exception was the direct cause " + "of the following exception:\n", file=efile) + elif (context is not None and + not exc.__suppress_context__ and + context not in seen): + print_exc(type(context), context, context.__traceback__) + print("\nDuring handling of the above exception, " + "another exception occurred:\n", file=efile) + if tb: + tbe = traceback.extract_tb(tb) + print('Traceback (most recent call last):', file=efile) + exclude = ("run.py", "rpc.py", "threading.py", "queue.py", + "RemoteDebugger.py", "bdb.py") + cleanup_traceback(tbe, exclude) + traceback.print_list(tbe, file=efile) + lines = traceback.format_exception_only(typ, exc) + for line in lines: + print(line, end='', file=efile) + + print_exc(typ, val, tb) def cleanup_traceback(tb, exclude): "Remove excluded traces from beginning/end of tb; get cached lines" |