Simplify implementation of print_chain.

This commit is contained in:
Ka-Ping Yee 2005-05-16 19:12:51 +00:00
parent 6d466b9e14
commit 2e09a4c99d
1 changed files with 7 additions and 14 deletions

View File

@ -295,20 +295,13 @@ Enhanced Reporting
or __context__ respectively. Here is a sketch of the procedure:
def print_chain(exc):
chain = []
link = None
while exc:
chain.append((exc, link))
if exc.__cause__:
exc, link = exc.__cause__, 'The above exception...'
else:
exc, link = exc.__context__, 'During handling...'
for exc, link in reversed(chain):
print_exc(exc)
if link:
print
print link
print
if exc.__cause__:
print_chain(exc.__cause__)
print '\nThe above exception was the direct cause...'
elif exc.__context__:
print_chain(exc.__context__)
print '\nDuring handling of the above exception, ...'
print_exc(exc)
In the 'traceback' module, the format_exception, print_exception,
print_exc, and print_last functions will be updated to accept an