a = 3
b = 4
c = 0
try:
a = a/c
except:
import sys, cgitb, traceback, inspect
tbt,tbv,tb = sys.exc_info()
print 'traceback\n',''.join(traceback.format_exception(t bt,tbv,tb))
print '\n\ncgitb\n',cgitb.text((tbt,tbv,tb),1)
raise_an_error()
The above script gives the error location as line 6 using
traceback.format_exception, but when the same triplet is passed to cgitb
formatters the error is recorded as coming from the line where cgitb.text is
called (or cgitb.html). Is this not an error?
The entire output from the script is below. At the very end the original
standard traceback is repeated inside cgitb.text and differs from the nicely
formatted version.
##############################
C:\code\rlinfra\test_utils>\tmp\eee.py
traceback
Traceback (most recent call last):
File "C:\tmp\eee.py", line 6, in raise_an_error
a = a/c
ZeroDivisionError: integer division or modulo by zero
cgitb
ZeroDivisionError
Python 2.3.2: C:\Python\python.exe
Mon May 10 16:00:40 2004
A problem occurred in a Python script. Here is the sequence of
function calls leading up to the error, in the order they occurred.
C:\tmp\eee.py in raise_an_error()
11 print '\n\ncgitb\n',cgitb.text((tbt,tbv,tb),1)
>>>>>>this looks wrong<<<<<<<<<<<<
cgitb = <module 'cgitb' from 'C:\Python\lib\cgitb.pyc'>
cgitb.text = <function text at 0x008EE930>
tbt = <class exceptions.ZeroDivisionError at 0x00864CC0>
tbv = <exceptions.ZeroDivisionError instance at 0x008ECF80>
tb = <traceback object at 0x008ECB98>
ZeroDivisionError: integer division or modulo by zero
__doc__ = 'Second argument to a division or modulo operation was zero.'
__getitem__ = <bound method ZeroDivisionError.__getitem__ of
<...ptions.ZeroDivisionError instance at 0x008ECF80>>
__init__ = <bound method ZeroDivisionError.__init__ of
<exceptions.ZeroDivisionError instance at 0x008ECF80>>
__module__ = 'exceptions'
__str__ = <bound method ZeroDivisionError.__str__ of
<exceptions.ZeroDivisionError instance at 0x008ECF80>>
args = ('integer division or modulo by zero',)
The above is a description of an error in a Python program. Here is
the original traceback:
Traceback (most recent call last):
File "C:\tmp\eee.py", line 6, in raise_an_error
a = a/c
ZeroDivisionError: integer division or modulo by zero
##############################
--
Robin Becker