问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/45505741/make-visual-studio-break-on-user-stdexception-exceptions