使Visual Studio在用户(std :: exception)异常上中断? [英] Make Visual Studio break on User (std::exception) Exceptions?

查看:152
本文介绍了使Visual Studio在用户(std :: exception)异常上中断?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



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



我知道

解决方案

调试器具有遇到麻烦,但是您没有在调用堆栈中显示最顶层的函数,而实际上却在引发异常。



您要显示的是栈底的函数。这表明,当当前正在调用的函数返回要执行的下一行时,该行就是 socket(...)行。这就是为什么该行上的图标是绿色的返回图标,而不是黄色的当前正在执行图标。



右键单击调用堆栈,单击'显示外部代码',您将看到类似的内容:

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

请注意,其 KernelBase.dll!RaiseException 实际从中引发异常的地方。



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


My code throws unhandled exceptions, but the debugger in Visual Studio only breaks on those thrown by the system.

For example, below the return value of getaddrinfo is not zero and my exception should be thrown first - in fact, if I place a breakpoint at line 171, it is hit - yet the debugger only breaks on the call to socket.

I know I have to add my own types explicitly, or else check All C++ Exceptions not in this list, in Exception Settings, but this is a std::exception I am throwing, and std::exception is checked.

How do I make the Visual Studio debugger break automatically on my exceptions?

解决方案

The debugger has broken on the throw but you're not showing the topmost function in the callstack which is actually raising the exception.

What you're showing is a function further down the stack. And what this shows is that when the function that's currently being called returns the next line to be executed is the socket(...) line. That is why the icon on that line is the little green 'return' icon and not the yellow 'execution is currently here' icon.

Right click on the callstack, click 'show external code' and you'll see something like:

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++

Note that its the KernelBase.dll!RaiseException where the exception is actually being thrown from.

Yes, I can agree this isn't very c++ like but throwing exceptions is a mechanism which requires complex code and so it happens like this.

这篇关于使Visual Studio在用户(std :: exception)异常上中断?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆