不使用logging
模块,只是简单的输出某一个函数的异常信息
# coding:utf-8
import sys
import pandas as pd
def test():
try:
pd.DataFrame('')
except ValueError:
error_msg = '执行异常![{0}]-[{1}:{2}]-[{3} {4}]】'.format(
sys.exc_info()[2].tb_frame.f_code.co_filename,
sys.exc_info()[2].tb_frame.f_code.co_name,
sys.exc_info()[2].tb_lineno,
sys.exc_info()[0],
sys.exc_info()[1]
)
print(error_msg)
test()
输出信息如下:
执行异常![E:\7、Projects\1、PythonProjects\测试.py]-[test:9]-[<class 'ValueError'> DataFrame constructor not properly called!]