如何在已处理的异常上停止 PyCharm 的中断/停止/停止功能(即仅在 python 未处理的异常上中断)?

Cha*_*ker 5 python debugging pycharm

我发现 PyCharm 停止处理我的所有异常,甚至是我在try except块中处理的异常。我不希望它在那里中断 - 我正在处理并且可能期待一个错误。但我确实希望它停止并暂停执行所有其他异常(例如,以便我拥有程序状态并对其进行调试)。

\n

如何做到这一点?

\n

我尝试进入 python 异常断点选项,但没有看到像“仅在未处理的异常上中断”这样的选项,例如:

\n\n

注意这是我当前的状态,注意它是如何在我的 try 块中停止的......:(

\n

交叉发布:https://intellij-support.jetbrains.com/hc/en-us/community/posts/4415666598546-How-to-stop-PyCharm-s-break-stop-halt-feature-on-handled-exceptions- ie-only-break-on-python-unhandled-exceptions-

\n

在此输入图像描述

\n
\n

我试过:

\n
In your link here intellij-support.jetbrains.com/hc/en-us/community/posts/\xe2\x80\xa6 the poster Okke said they solved this issue adding --pdb to the \'addition arguments\', which someone later said they probably meant interpreter options.\n
Run Code Online (Sandbox Code Playgroud)\n

但没有工作并出现错误:

\n
/Users/brandomiranda/opt/anaconda3/envs/meta_learning/bin/python --pdb /Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py --cmd-line --multiproc --qt-support=auto --client 127.0.0.1 --port 58378 --file /Users/brandomiranda/ultimate-utils/tutorials_for_myself/try_catch_pycharm_issues/try_catch_with_pickle.py\nunknown option --pdb\nusage: /Users/brandomiranda/opt/anaconda3/envs/meta_learning/bin/python [option] ... [-c cmd | -m mod | file | -] [arg] ...\nTry `python -h\' for more information.\n\nProcess finished with exit code 2\n
Run Code Online (Sandbox Code Playgroud)\n

小智 2

我认为它实际上已经在工作了,但实际上您没有发现正确的错误。在你的代码中你有:

try:
    pickle.dumps(obj)
except pickle.PicklingError:
    return False
Run Code Online (Sandbox Code Playgroud)

但抛出的错误是AttributeError. 因此,为了避免这种情况,您需要这样的东西:

try:
    pickle.dumps(obj)
except (pickle.PicklingError, AttributeError):
    return False
Run Code Online (Sandbox Code Playgroud)