Is there a way to do something like DebugBreak() where when that function is hit the debugger breaks, but continue running when no debugger is attached?
I have a lua error handler that presents a user-friendly error message when something goes wrong, but if I'm debugging I want to stop execution as soon as I've detected something wrong.
I don't want to set a breakpoint in the debugger UI. I want a line of code that causes the debugger to break so I can share this breakpoint with co-workers.
You can use IsDebuggerPresent
to check for an attached debugger, and then conditionally invoke DebugBreak
:
if (IsDebuggerPresent()) {
DebugBreak();
}