By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,427 Members | 1,354 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,427 IT Pros & Developers. It's quick & easy.

Reporting the line number of an exception

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.