【问题标题】:Make Visual Studio break on User (std::exception) Exceptions?让 Visual Studio 中断用户(std::exception)异常?
【发布时间】:2018-01-12 07:54:47
【问题描述】:

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

例如,getaddrinfo 的返回值以下不为零,应该首先抛出我的异常——事实上,如果我在第 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 调试器在我的异常中自动中断?

【问题讨论】:

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


    【解决方案1】:

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

    您所展示的是堆栈更下方的一个函数。这表明当当前被调用的函数返回要执行的下一行是socket(...) 行。这就是为什么该行上的图标是绿色的“返回”小图标,而不是黄色的“当前正在执行”图标。

    右键单击调用堆栈,单击“显示外部代码”,您会看到如下内容:

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

    【讨论】:

      猜你喜欢
      • 2012-05-07
      • 1970-01-01
      • 2011-08-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-25
      • 1970-01-01
      • 2013-06-02
      • 2019-10-06
      相关资源
      最近更新 更多