def raise_an_error( ):
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(tracebac k.format_except ion(tbt,tbv,tb) )
print '\n\ncgitb\n',c gitb.text((tbt, tbv,tb),1)
raise_an_error( )
The above script gives the error location as line 6 using
traceback.forma t_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>\tm p\eee.py
traceback
Traceback (most recent call last):
File "C:\tmp\eee.py" , line 6, in raise_an_error
a = a/c
ZeroDivisionErr or: integer division or modulo by zero
cgitb
ZeroDivisionErr or
Python 2.3.2: C:\Python\pytho n.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',c gitb.text((tbt, tbv,tb),1)[color=blue][color=green][color=darkred]
>>>>>>>>>>thi s looks wrong<<<<<<<<<< <<[/color][/color][/color]
cgitb = <module 'cgitb' from 'C:\Python\lib\ cgitb.pyc'>
cgitb.text = <function text at 0x008EE930>
tbt = <class exceptions.Zero DivisionError at 0x00864CC0>
tbv = <exceptions.Zer oDivisionError instance at 0x008ECF80>
tb = <traceback object at 0x008ECB98>
ZeroDivisionErr or: integer division or modulo by zero
__doc__ = 'Second argument to a division or modulo operation was zero.'
__getitem__ = <bound method ZeroDivisionErr or.__getitem__ of
<...ptions.Zero DivisionError instance at 0x008ECF80>>
__init__ = <bound method ZeroDivisionErr or.__init__ of
<exceptions.Zer oDivisionError instance at 0x008ECF80>>
__module__ = 'exceptions'
__str__ = <bound method ZeroDivisionErr or.__str__ of
<exceptions.Zer oDivisionError 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
ZeroDivisionErr or: integer division or modulo by zero
############### ###############
--
Robin Becker
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(tracebac k.format_except ion(tbt,tbv,tb) )
print '\n\ncgitb\n',c gitb.text((tbt, tbv,tb),1)
raise_an_error( )
The above script gives the error location as line 6 using
traceback.forma t_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>\tm p\eee.py
traceback
Traceback (most recent call last):
File "C:\tmp\eee.py" , line 6, in raise_an_error
a = a/c
ZeroDivisionErr or: integer division or modulo by zero
cgitb
ZeroDivisionErr or
Python 2.3.2: C:\Python\pytho n.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',c gitb.text((tbt, tbv,tb),1)[color=blue][color=green][color=darkred]
>>>>>>>>>>thi s looks wrong<<<<<<<<<< <<[/color][/color][/color]
cgitb = <module 'cgitb' from 'C:\Python\lib\ cgitb.pyc'>
cgitb.text = <function text at 0x008EE930>
tbt = <class exceptions.Zero DivisionError at 0x00864CC0>
tbv = <exceptions.Zer oDivisionError instance at 0x008ECF80>
tb = <traceback object at 0x008ECB98>
ZeroDivisionErr or: integer division or modulo by zero
__doc__ = 'Second argument to a division or modulo operation was zero.'
__getitem__ = <bound method ZeroDivisionErr or.__getitem__ of
<...ptions.Zero DivisionError instance at 0x008ECF80>>
__init__ = <bound method ZeroDivisionErr or.__init__ of
<exceptions.Zer oDivisionError instance at 0x008ECF80>>
__module__ = 'exceptions'
__str__ = <bound method ZeroDivisionErr or.__str__ of
<exceptions.Zer oDivisionError 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
ZeroDivisionErr or: integer division or modulo by zero
############### ###############
--
Robin Becker
Comment