including column information when an exception occurs
Michael McCandless
mail at mikemccandless.com
Sat Dec 4 13:05:46 EST 1999
Hi,
When a Python exception occurs, the interpreter shows you the stack
traceback to the line where the error occurred. Why, when it gets down
to the actual line, does it not also report, eg, the column or
subexpression in which the error occurs?
This would be useful when you have lines that have a fair number of
operations such that the exception could have come from more than one
sub-expression.
EG, in the following program:
def test0(tup, i0, i1):
test1(tup, i0, i1)
def test1(tup, i0, i1):
return tup[i0] + tup[i1]
test0((1, 2, 3), 2, 4)
This exception is generated:
Traceback (innermost last):
File "test2.py", line 7, in ?
test0((1, 2, 3), 2, 4)
File "test2.py", line 2, in test0
test1(tup, i0, i1)
File "test2.py", line 5, in test1
return tup[i0] + tup[i1]
IndexError: tuple index out of range
But, it's unclear which tuple reference caused the IndexError...
Mike
More information about the Python-list
mailing list