Skip to content

Instantly share code, notes, and snippets.

@olliebun
Created July 14, 2013 23:47
Show Gist options
  • Save olliebun/5996606 to your computer and use it in GitHub Desktop.
Save olliebun/5996606 to your computer and use it in GitHub Desktop.
Get exception line number
import sys
try:
raise ValueError("Damn")
except ValueError as e:
_, _, exc_tb = sys.exc_info()
# print the file that threw the exception
print(exc_tb.tb_frame.f_code.co_filename)
# print the line number of the expression that threw the exception
print(exc_tb.tb_lineno)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment