python-3.x - 即使在 python 中的 try catch 中,如何让 vscode 调试器停止?

标签 python-3.x visual-studio visual-studio-code vscode-debugger

看到建议为“相似”的问题,似乎大多数人想要的与我想要的相反。我想要的是 Vs-code 的调试器在错误点停止,即使在 try catch 中(通常会这样做)。
但是,当在像这样的 try catch 中时,它所做的并不是停止:

import traceback 

try:
    main() # has bugs I'm trying to debug
except Exception as e:
    send_email(traceback.format_exc())
    send_email(e)
我知道这可能是一件奇怪的事情,并且 vs-code 的调试器可能运行正确(因为我的代码告诉它如何处理异常!)但我有一些错误,我想调试而不是捕捉。事实上,我的外部 try catch 就在那里,因为我正在使用一个集群,当有任何错误时,它会向我发送电子邮件并告诉我有关它们的信息。否则我就不会在我的主要代码周围有一个 try catch 。
当我实际调试时,有没有办法告诉 vs-code 忽略我的 try catch ?

我在写这篇文章时的一个想法是改变我捕捉到的异常类型……虽然在调试期间我希望它总是停止,而在不调试时我希望它永远不会停止并向我发送一封包含漏洞。
有任何想法吗?

新错误:
Exception has occurred: TypeError
catching classes that do not inherit from BaseException is not allowed
使用我的 EmptyException 时回答:
class EmptyError(Exception):
    def __init__(self):
        pass

最佳答案

这可能是一种非常愚蠢的方法,但是当我在 Debug模式下运行时,我有一个设置为 true 的标志:

args.debug = True

然后基于该标志,我设置了异常类型:
if args.debug:
    args.ExceptionType = Exception
else:
    args.ExceptionType = EmptyError

哪里EmptyError是一个不做任何事情的自定义异常,只是当我在 Debug模式下运行时 VS 代码停止:
class EmptyError(Exception):
    def __init__(self):
        pass

有点愚蠢,但我不知道什么更好。

关于python-3.x - 即使在 python 中的 try catch 中,如何让 vscode 调试器停止?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61578959/

相关文章:

visual-studio-code - Live Sass 编译器 - @use 导致编译错误

c# - 我如何在 C# 中找出某些东西是结构(值类型)或类(引用类型)

intellisense - VSCode - 为什么 tsconfig.json 必须在根目录中才能自动完成?

python - 在数据 block 上安装新版本后,pandas 版本未更新

python - 在 numpy 矩阵中存储字符串

python - Kivy标签代码从kivy语言转python

python-3.x - 来自多个文件的Python多线程

visual-studio - 更新 Xamarin 后,我得到引用的组件 *** 无法找到

c++ - 静态和动态 MFC 链接

visual-studio-code - VS Code : How to reduce the minimum window size of Visual Studio Code through settings. json 或其他一些方法