python 捕获异常详细信息

import os
import sys
import traceback
BasePath = os.path.dirname(os.getcwd())
sys.path.append(BasePath)

from src import main

if __name__ == '__main__':
    try:
        main.run()
    except Exception as e:

        with open('error.log','a') as f:
            f.write('*' * 100 + "\n")
            f.write(traceback.format_exc())  # 使用 traceback.format_exc() 获取异常详细信息
            f.write('*' * 100 + "\n")

 

posted on 2017-05-12 09:12  奋斗中的码农  阅读(1141)  评论(0编辑  收藏  举报

导航