程序错误、异常写入文档中示例

import traceback
try:
    raise Exception('这是一个错误信息')
except:
    errFile=open('err.txt','w')
    errFile.write(traceback.format_exc())
    errFile.close()
    print('错误信息已经写入err.txt文件中')
原文地址:https://www.cnblogs.com/chenxi188/p/10523957.html