Answers for "get error line number python"

2

exception get line number python

import traceback

try:
    print(4/0)
except ZeroDivisionError:
    print(traceback.format_exc())
Posted by: Guest on January-28-2021
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
0

python error get line

import sys
try:
    print(5/0)
except Exception as e:
    print('Error on line {}'.format(sys.exc_info()[-1].tb_lineno), type(e).__name__, e)

print('And the rest of program continues')
Posted by: Guest on September-09-2021

Code answers related to "get error line number python"

Python Answers by Framework

Browse Popular Code Answers by Language