Make Visual Studio break on User (std :: exception) Exceptions?

My code throws unhandled exceptions, but the debugger in Visual Studio only breaks into those that the system throws.

For example, the return value of getaddrinfo below is not zero, and my exception should be the first to be selected - in fact, if I put a breakpoint on line 171, it gets caught - but the debugger only breaks the socket call.

I know I need to add my own types explicitly, or check All C++ Exceptions not in this list , in Exception Settings , but this is std::exception , I throw, and std::exception .

How to make the Visual Studio debugger automatically break into my exceptions?

enter image description here

+5
source share
1 answer

The debugger crashed into a throw, but you do not show the topmost function in the freeze frame, which actually raises an exception.

What you are showing is a function down the stack. And this shows that when the function that is currently being called returns the next line to be executed, it is the socket(...) . This is why the icon on this line is the green "return" icon, and not the yellow "Currently running here" icon.

Right-click on the stop-bone, click "show external code", and you will 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 KernelBase.dll!RaiseException where the exception is actually thrown.

Yes, I can agree that this is not very similar to C ++, but throwing exceptions is a mechanism that requires complex code, and therefore it happens.

+3
source

Source: https://habr.com/ru/post/1270581/


All Articles