如何在不停止程序的情况下打印完整的回溯?

扶醉桌前 提交于 2020-08-08 00:49:46

问题:

I'm writing a program that parses 10 websites, locates data files, saves the files, and then parses them to make data that can be readily used in the NumPy library. 我正在编写一个程序,该程序可以解析10个网站,找到数据文件,保存文件,然后解析它们以生成可以在NumPy库中轻松使用的数据。 There are tons of errors this file encounters through bad links, poorly formed XML, missing entries, and other things I've yet to categorize. 有过不良链接,不好的XML,缺项,其他的事情我还没有进行分类文件遭遇的错误。 I initially made this program to handle errors like this: 我最初制作该程序来处理以下错误:

try:
    do_stuff()
except:
    pass

But now I want to log errors: 但是现在我想记录错误:

try:
    do_stuff()
except Exception, err:
    print Exception, err

Note this is printing to a log file for later review. 请注意,这是打印到日志文件以供以后查看。 This usually prints very useless data. 这通常会打印非常无用的数据。 What I want is to print the exact same lines printed when the error triggers without the try-except intercepting the exception, but I don't want it to halt my program since it is nested in a series of for loops that I would like to see to completion. 我想要的是在错误触发时打印完全相同的行,而没有try-except拦截异常,但是我不希望它暂停我的程序,因为它嵌套在我想要的一系列for循环中看到完成。


解决方案:

参考一: https://stackoom.com/question/FXEZ/如何在不停止程序的情况下打印完整的回溯
参考二: https://oldbug.net/q/FXEZ/How-to-print-the-full-traceback-without-halting-the-program
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!