Reputation: 5124
I'm trying to implement in c++/Windows the "Debugger Main Loop" described in this article: Writing the Debugger's Main Loop
But I want any thrown exception to display an error message to the secreen and be caught by the debugger.
I understood that I can do this by giving ContinueDebugEvent
some value of DBG_??? but I don't know what it is.
What is this value?
I also noticed that console applications notify the debugger of exceptions when something is written to the console.
How can I filter actual exception from those things? Does it have anything to do with the "first chance" value?
thanks :)
Upvotes: 2
Views: 918
Reputation: 5769
The debugger receives an exception event for every exception that occurs in the debuggee.
If you pass DBG_CONTINUE
to ContinueDebugEvent
, the debugger swallows the exception and execution continues as if no exception happened in the first place. That means that the debuggee is not notified of it either.
If on the other hand you pass DBG_EXCEPTION_NOT_HANDLED
the debuggee is notified and responsible for handling the exception.
Now, if the debuggee does not handle (read: catch) the exception, the debugger gets notified a second time, this time with Event.u.Exception.dwFirstChance
set to 0. At this point the exception would terminate the process if you pass DBG_EXCEPTION_NOT_HANDLED
.
Two things to keep in mind:
OutputDebugString
. No need to use self-defined exceptions unless you need to pass something other than a string.Event.u.Exception.ExceptionRecord.ExceptionCode
and see if it matches your predefined exception type and use DBG_CONTINUE
in that case.Upvotes: 4