467,894 Members | 1,724 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,894 developers. It's quick & easy.

Reporting the line number of an exception

I'm sure this is exceedingly simple but I can't find it anywhere. When
I catch an exception I would like to report the line number of the
exception as well as the error info.

try:
someError()
except Exception, e:
"print_error_and_line_number"

How do I find the line number?

Thanks for any help!
Jun 27 '08 #1
  • viewed: 13107
Share:
1 Reply
sophie_newbie wrote:
I'm sure this is exceedingly simple but I can't find it anywhere. When
I catch an exception I would like to report the line number of the
exception as well as the error info.

try:
someError()
except Exception, e:
"print_error_and_line_number"

How do I find the line number?
If you want just the line number:

tb = sys.exc_info()[2]
print tb.tb_lineno

You may also have a look at the traceback module, e. g.:

traceback.print_exc()

Peter
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by steve | last post: by
4 posts views Thread by Fabian von Romberg | last post: by
6 posts views Thread by John Lau | last post: by
reply views Thread by MrMoon | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.