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?
Tell the debugger to break when an exception is thrownIn the Exception Settings window (Debug > Windows > Exception Settings), expand the node for a category of exceptions, such as Common Language Runtime Exceptions. Then select the check box for a specific exception within that category, such as System.
Note: you can uncheck Break when this exception type is thrown directly in the exception handler and continue debugging (press F5 ). Visual Studio will add this exception type to the Exception settings and will remember that it shouldn't break on this exception again.
In Visual Studio, when exceptions are thrown or end up unhandled, the debugger can help you debug these by breaking just like it breaks when a breakpoint is hit.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With