使 Visual Studio 中断用户 (std::exception) 异常?

Make Visual Studio break on User (std::exception) Exceptions?

我的代码抛出未处理的异常,但 Visual Studio 中的调试器只中断系统抛出的异常。

例如,getaddrinfo 的 return 值不为零,我的异常应该首先抛出 - 事实上,如果我在第 171 行放置一个断点,它会被命中 - 然而调试器仅在调用 socket.

时中断

我知道I have to add my own types explicitly, or else check All C++ Exceptions not in this list,在Exception Settings,但这是我扔的std::exception,而std::exception已检查。

如何让 Visual Studio 调试器在出现异常时自动中断?

调试器在抛出时中断,但您没有显示实际上引发异常的调用堆栈中最顶层的函数。

您所展示的是堆栈下方的一个函数。这表明,当当前正在调用的函数 returns 时,下一行要执行的是 socket(...) 行。这就是为什么该行上的图标是小绿色 'return' 图标而不是黄色 'execution is currently here' 图标的原因。

右键单击调用堆栈,单击 'show external code',您将看到如下内容:

KernelBase.dll!RaiseException(unsigned long dwExceptionCode, unsigned long dwExceptionFlags, unsigned long nNumberOfArguments, const unsigned long * lpArguments) Line 904  C
vcruntime140d.dll!_CxxThrowException(void * pExceptionObject, const _s__ThrowInfo * pThrowInfo) Line 136    C++
ConsoleApplication5.exe!main() Line 6   C++
ConsoleApplication5.exe!invoke_main() Line 64   C++

请注意,它是 KernelBase.dll!RaiseException 实际抛出异常的地方。

是的,我同意这不是很像 C++,但抛出异常是一种需要复杂代码的机制,所以它是这样发生的。