gpt4 book ai didi

python - 如何获取有关 Python 线程异常的完整信息?

转载 作者:太空宇宙 更新时间:2023-11-04 06:17:26 24 4
gpt4 key购买 nike

当线程中发生异常时,我得到的不是包含异常行号的完整异常信息,而是:

Unhandled exception in thread started by <function get_artist at 0x0000000002C2FEB8>

我可以手动编写 try、catch 过程来打印出有关异常的缺失信息吗?

我试过:

except Exception:
traceback.print_exc()

但是,它仍然只打印上面的消息。

最佳答案

您是否尝试过使用 as 获取异常?像这样的……

try:
raise Exception('MONSTER!')
except Exception as ex:
print 'The error is a %s' % ex

>>> The error is a MONSTER!

关于python - 如何获取有关 Python 线程异常的完整信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14690729/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com