En Fri, 19 Sep 2008 10:40:00 -0300, Alexandru Mosoi <[EMAIL PROTECTED]>
escribió:
i have a generator that raises an exception when calling next(),
however if I try to catch the exception and print the traceback i get
only the line where next() was called
while True:
try:
iterator.next()
except StopIteration:
break
except Exception, e:
traceback.print_exc()
how do I get the traceback starting from where exception was raised in
first place?
I get a complete traceback:
py> import traceback
py>
py> def a(x):
... raise ValueError
...
py> def b(x):
... return a(x)
...
py> def c(n):
... for i in range(n):
... yield b(i)
...
py> it = c(5)
py> while True:
... try:
... it.next()
... except StopIteration:
... break
... except Exception:
... print traceback.print_exc()
...
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
File "<stdin>", line 3, in c
File "<stdin>", line 2, in b
File "<stdin>", line 2, in a
ValueError
None
py>
Could you provide a more complete example that fails?
--
Gabriel Genellina
--
http://mail.python.org/mailman/listinfo/python-list