gpt4 book ai didi

python - 在 except block 中引发异常并抑制第一个错误

转载 作者:太空狗 更新时间:2023-10-29 20:14:19 24 4
gpt4 key购买 nike

<分区>

我正在 try catch 异常并在我的代码中的某个位置引发更具体的错误:

try:
something_crazy()
except SomeReallyVagueError:
raise ABetterError('message')

这在 Python 2 中有效,但在 Python 3 中,它显示了两个异常:

Traceback(most recent call last):
...
SomeReallyVagueError: ...
...

During handling of the above exception, another exception occurred:

Traceback(most recent call last):
...
ABetterError: message
...

有什么方法可以解决这个问题,从而不显示 SomeReallyVagueError 的回溯?

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