异常处理 - python try...except中如何输入e的行号
本文介绍了异常处理 - python try...except中如何输入e的行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
try:
print(aaa)
except Exception as e:
print(e)
解决方案
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)
提问前请先上网搜索。
python-when-i-catch-an-exception-how-do-i-get-the-type-file-and-line-number
这篇关于异常处理 - python try...except中如何输入e的行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文