def showtraceback(self):
"""Display the exception that just occurred.
We remove the first stack item because it is our own code.
The output is written by self.write(), below.
"""
sys.last_type, sys.last_value, last_tb = ei = sys.exc_info()
sys.last_traceback = last_tb
try:
lines = []
for value, tb in traceback._iter_chain(*ei[1:]):
if isinstance(value, str):
lines.append(value)
lines.append('\n')
continue
if tb:
tblist = traceback.extract_tb(tb)
if tb is last_tb:
# The last traceback includes the frame we
# exec'd in
del tblist[:1]
tblines = traceback.format_list(tblist)
if tblines:
lines.append("Traceback (most recent call last):\n")
lines.extend(tblines)
lines.extend(traceback.format_exception_only(type(value),
value))
finally:
tblist = last_tb = ei = None
self.write(''.join(lines))
评论列表
文章目录