mirror of
https://github.com/python/cpython.git
synced 2025-10-17 12:18:23 +00:00
Issue #16491: IDLE now prints chained exception tracebacks.
This commit is contained in:
parent
48e188e573
commit
78470b4c3a
2 changed files with 28 additions and 9 deletions
|
@ -158,16 +158,33 @@ def print_exception():
|
||||||
efile = sys.stderr
|
efile = sys.stderr
|
||||||
typ, val, tb = excinfo = sys.exc_info()
|
typ, val, tb = excinfo = sys.exc_info()
|
||||||
sys.last_type, sys.last_value, sys.last_traceback = excinfo
|
sys.last_type, sys.last_value, sys.last_traceback = excinfo
|
||||||
|
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 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)
|
tbe = traceback.extract_tb(tb)
|
||||||
print('Traceback (most recent call last):', file=efile)
|
print('Traceback (most recent call last):', file=efile)
|
||||||
exclude = ("run.py", "rpc.py", "threading.py", "queue.py",
|
exclude = ("run.py", "rpc.py", "threading.py", "queue.py",
|
||||||
"RemoteDebugger.py", "bdb.py")
|
"RemoteDebugger.py", "bdb.py")
|
||||||
cleanup_traceback(tbe, exclude)
|
cleanup_traceback(tbe, exclude)
|
||||||
traceback.print_list(tbe, file=efile)
|
traceback.print_list(tbe, file=efile)
|
||||||
lines = traceback.format_exception_only(typ, val)
|
lines = traceback.format_exception_only(typ, exc)
|
||||||
for line in lines:
|
for line in lines:
|
||||||
print(line, end='', file=efile)
|
print(line, end='', file=efile)
|
||||||
|
|
||||||
|
print_exc(typ, val, tb)
|
||||||
|
|
||||||
def cleanup_traceback(tb, exclude):
|
def cleanup_traceback(tb, exclude):
|
||||||
"Remove excluded traces from beginning/end of tb; get cached lines"
|
"Remove excluded traces from beginning/end of tb; get cached lines"
|
||||||
orig_tb = tb[:]
|
orig_tb = tb[:]
|
||||||
|
|
|
@ -199,6 +199,8 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #16491: IDLE now prints chained exception tracebacks.
|
||||||
|
|
||||||
- Issue #16828: Fix error incorrectly raised by bz2.compress(''). Patch by
|
- Issue #16828: Fix error incorrectly raised by bz2.compress(''). Patch by
|
||||||
Martin Packman.
|
Martin Packman.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue