Simplify implementation of print_chain.
This commit is contained in:
parent
6d466b9e14
commit
2e09a4c99d
21
pep-0344.txt
21
pep-0344.txt
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue