Created
August 27, 2015 20:17
-
-
Save avenet/ff84c552127b0547cd56 to your computer and use it in GitHub Desktop.
Get exception line number
This file contains hidden or 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 | |
import traceback | |
try: | |
exec(open('error.py').read()) | |
except Exception as e: | |
exc_type, ex, tb = sys.exc_info() | |
imported_tb_info = traceback.extract_tb(tb)[-1] | |
line_number = imported_tb_info[1] | |
print('{}: Exception in line: {}, message: {}'.format(exc_type.__name__, line_number, ex)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment