看到建议为“相似”的问题,似乎大多数人想要的与我想要的相反。我想要的是 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/