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

时间:2017-08-04 11:32:38

标签: c++ exception-handling visual-studio-2017 visual-studio-debugging

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

例如,低于getaddrinfo的返回值不为零,我的异常应该首先抛出 - 实际上,如果我在第171行放置一个断点,它会被命中 - 但是调试器只会在致电socket

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

如何在我的例外情况下自动中断Visual Studio调试器?

enter image description here

1 个答案:

答案 0 :(得分:3)

调试器已经中断,但是你没有显示callstack中最顶层的函数,它实际上是在引发异常。

你所展示的是进一步向下的功能。这表明当当前被调用的函数返回下一行要执行的是socket(...)行时。这就是为什么那条线上的图标是小绿色'返回'图标而不是黄色的执行目前在这里'图标。

右键单击callstack,点击'显示外部代码'你会看到类似的东西:

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 ++,但抛出异常是一种需要复杂代码的机制,所以它就像这样发生。

相关问题