Is it possible to executed only while debugging NOT _DEBUG MODE

I use __debugbreak() like this.

1
2
3
4
5
6
#ifdef _DEBUG
if(~)
{
    __debugbreak();
}
#endif 


If this code executed while debugging, then maybe stopped at there without terminated.
But if this code executed while not debugging but still debug mode, then the program will be terminated.

Is there any good way?
I'm not sure what you mean by not debugging but still in debug mode. Are you saying that you compiled a debug version of the software but may or may not be running through a debugger?

In that case, if you want to stop at this line, simply put a breakpoint there. When you run it through the debugger, the code will stop at that point.

And, based on what you stated, you probably don't even need any of the code you showed. Simply put the breakpoint on the next line. Your debugger will stop right before that line is executed.
Do you want to drop into the debugger automatically, if you're running a debug enabled program outside of your IDE?
yes, I meant about running with a debugger. I know when the program(run through a debugger) meets the __debugbreak() line, the program will be stopped at the line instead terminated.

but if the program run without a VS debugger, the program will be terminated instead stopped. Right?

I want a effect of __debugbreak in the program which run through a debugger.

but I don't want a effect of __debugbreak in the program which doesn't run through a debugger.

Last edited on
Topic archived. No new replies allowed.