(original) (raw)

Index: code.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/code.py,v retrieving revision 1.22 diff -c -r1.22 code.py *** code.py 13 Feb 2003 22:07:53 -0000 1.22 --- code.py 28 Jun 2005 06:36:29 -0000 *************** *** 109,114 **** --- 109,130 ---- if softspace(sys.stdout, 0): print + def showexception(self, stack_size): + """Show current exception + + We need to skip 'stack_size' tracebacks to get to the "real" cause + + """ + type, value, tb = sys.exc_info() + try: + for i in range(stack_size): + tb = tb.tb_next + + sys.excepthook(type, value, tb) + finally: + tb = None + + def showsyntaxerror(self, filename=None): """Display the syntax error that just occurred. *************** *** 121,165 **** The output is written by self.write(), below. """ ! type, value, sys.last_traceback = sys.exc_info() ! sys.last_type = type ! sys.last_value = value ! if filename and type is SyntaxError: ! # Work hard to stuff the correct filename in the exception ! try: ! msg, (dummy_filename, lineno, offset, line) = value ! except: ! # Not the format we expect; leave it alone ! pass ! else: ! # Stuff in the right filename ! value = SyntaxError(msg, (filename, lineno, offset, line)) ! sys.last_value = value ! list = traceback.format_exception_only(type, value) ! map(self.write, list) 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. - """ ! try: ! type, value, tb = sys.exc_info() ! sys.last_type = type ! sys.last_value = value ! sys.last_traceback = tb ! tblist = traceback.extract_tb(tb) ! del tblist[:1] ! list = traceback.format_list(tblist) ! if list: ! list.insert(0, "Traceback (most recent call last):\n") ! list[len(list):] = traceback.format_exception_only(type, value) ! finally: ! tblist = tb = None ! map(self.write, list) def write(self, data): """Write a string. --- 137,152 ---- The output is written by self.write(), below. """ ! self.showexception(3) ! def showtraceback(self): """Display the exception that just occurred. We remove the first stack item because it is our own code. """ ! self.showexception(1) def write(self, data): """Write a string.