Getting the line where an exception is raised
JB
jb at yahoo.de
Fri Oct 11 11:17:08 EDT 2002
Steve Holden wrote:
Thank you vey much, but your suggestion does not really
help. Here is my code:
try:
exec tmp in user_name_space
except:
txt = str(sys.exc_info()[1])
i = traceback.tb_lineno(sys.exc_info()[2])
print '*',txt,'*',i,'*'
mw.widget.text.eingabe.setCursorPosition(i,0)
mw.widget.text.ausgabe.setReadOnly(0)
mw.widget.text.ausgabe.setText('<font color=red>
'+txt+'</font>')
mw.widget.text.ausgabe.setReadOnly(1)
(I use PyQt.)
Now I always receive the line number 41 from
traceback.tb_lineno(sys.exc_info()[2]),
as the exec statement happens to be in the 41th line of my
code. But the error message say somthig like "syntax error
in (line 11)" and /this/ line number is ok. (tmp contains
several lines of code.)
--
J.... B....
-----------== Posted via Newsfeed.Com - Uncensored Usenet News ==----------
http://www.newsfeed.com The #1 Newsgroup Service in the World!
-----= Over 100,000 Newsgroups - Unlimited Fast Downloads - 19 Servers =-----
More information about the Python-list
mailing list