python except 获取对应行数 捕获异常行数

通过.traceback.tb_lineno获取

try:
  print(asd)
except Exception as e:
 print('Except:',e,"Line:",e.__traceback__.tb_lineno)

你可能感兴趣的:(python except 获取对应行数 捕获异常行数)