Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 78470b4

Browse files
Issue #16491: IDLE now prints chained exception tracebacks.
1 parent 48e188e commit 78470b4

2 files changed

Lines changed: 28 additions & 9 deletions

File tree

Lib/idlelib/run.py

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,32 @@ def print_exception():
158158
efile = sys.stderr
159159
typ, val, tb = excinfo = sys.exc_info()
160160
sys.last_type, sys.last_value, sys.last_traceback = excinfo
161-
tbe = traceback.extract_tb(tb)
162-
print('Traceback (most recent call last):', file=efile)
163-
exclude = ("run.py", "rpc.py", "threading.py", "queue.py",
164-
"RemoteDebugger.py", "bdb.py")
165-
cleanup_traceback(tbe, exclude)
166-
traceback.print_list(tbe, file=efile)
167-
lines = traceback.format_exception_only(typ, val)
168-
for line in lines:
169-
print(line, end='', file=efile)
161+
seen = set()
162+
163+
def print_exc(typ, exc, tb):
164+
seen.add(exc)
165+
context = exc.__context__
166+
cause = exc.__cause__
167+
if cause is not None and cause not in seen:
168+
print_exc(type(cause), cause, cause.__traceback__)
169+
print("\nThe above exception was the direct cause "
170+
"of the following exception:\n", file=efile)
171+
elif context is not None and context not in seen:
172+
print_exc(type(context), context, context.__traceback__)
173+
print("\nDuring handling of the above exception, "
174+
"another exception occurred:\n", file=efile)
175+
if tb:
176+
tbe = traceback.extract_tb(tb)
177+
print('Traceback (most recent call last):', file=efile)
178+
exclude = ("run.py", "rpc.py", "threading.py", "queue.py",
179+
"RemoteDebugger.py", "bdb.py")
180+
cleanup_traceback(tbe, exclude)
181+
traceback.print_list(tbe, file=efile)
182+
lines = traceback.format_exception_only(typ, exc)
183+
for line in lines:
184+
print(line, end='', file=efile)
185+
186+
print_exc(typ, val, tb)
170187

171188
def cleanup_traceback(tb, exclude):
172189
"Remove excluded traces from beginning/end of tb; get cached lines"

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,8 @@ Core and Builtins
199199
Library
200200
-------
201201

202+
- Issue #16491: IDLE now prints chained exception tracebacks.
203+
202204
- Issue #16828: Fix error incorrectly raised by bz2.compress(''). Patch by
203205
Martin Packman.
204206

0 commit comments

Comments
 (0)