Answers for "how to get the line in which an exception occurred in python"

1

python get line number of error

import sys, os

try:
    raise NotImplementedError("No error")
except Exception as e:
    exc_type, exc_obj, exc_tb = sys.exc_info()
    fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
    print(exc_type, fname, exc_tb.tb_lineno)
Posted by: Guest on January-13-2021

Code answers related to "how to get the line in which an exception occurred in python"

Python Answers by Framework

Browse Popular Code Answers by Language