excepthook doesn't give exact line number
hpsekhon at googlemail.com
Thu Oct 5 13:40:11 CEST 2006
Thanks for the pointer, I've now got this giving me the right line
number when an exception occurs, although I still get an empty stack
print "Stack Trace:\n%s\n" % str(traceback.print_exc(2))
inside the excepthook.
Any ideas why this is?
Is there no traceback since the traceback was fed to the excepthook? Is
there another way of getting the traceback like you see when the
exception isn't caught?
Thanks for the help.
Peter Otten wrote:
> Hari Sekhon wrote:
>> The problem is that the excepthook gives the line of the topmost called
>> function rather that the actual line that generated the error the way
>> you get it with a normal traceback.
> A look into the traceback module shows that tracebacks are stored as a
> linked list. Here's a way to get hold of its tail:
> def tbiter(tb):
> while tb is not None:
> yield tb
> tb = tb.tb_next
> def last(items):
> for item in items:
> return item
> # example usage
> def myexcepthook(type, value, tb):
> tb_tail = last(tbiter(tb))
> print tb_tail.tb_lineno
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list