Created
July 14, 2013 23:47
-
-
Save olliebun/5996606 to your computer and use it in GitHub Desktop.
Get exception line number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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