I want to make an extension to quickly toggle breaking on CLR exceptions in debugger.
I have made tried several approaches, neither of which is satisfactory.
Here is what I have already tried:
ExceptionSettings.SetBreakWhenThrown
(MSDN)
This is extremely slow (see this Connect issue). I have tried approaches from question "Toggle “Break when an exception is thrown.” using macro or keyboard shortcut" and neither seem to work reliably: in most cases only top level checkbox gets set, and it does not actually break on exceptions when debugging.Call
DTE.ExecuteCommand("Debug.Exceptions")
to show the window, and callSetWindowsHookEx
(MSDN) just before that to intercept it before it appears (so that there is no flash to the user). This seems possible as I was able to intercept the message and getHWND
. But it seems hacky and window is not that easy to manipulate properly (it has some weird combination ofSysListView32
with custom checkboxes andSysTreeView32
). So I am leaving it as a last chance solution.Somehow get
IDebugEngine2
(MSDN) for managed code and callIDebugEngine2.SetException
(MSDN) at the start of the debugging session. This seems possible, but I am having problems getting a debug engine. I have tried approach withIVsLoader
described on MSDN forums, but I am pretty sure it gives me a new instance unrelated to the debugging session.I have also asked the question here: "Visual Studio: How to get IDebugEngine2 from VS Package (except IVsLoader)", but did not get a solution.
I have tried using
IVsDebugger.AdviseDebugEventCallback
(MSDN) and passing in implementation ofIDebugEventCallback2
(MSDN), but I am always gettingnull
forpEngine
(and noIDebugEngineCreateEvent2
either).I do get
IDebugSessionCreateEvent2
(undocumented?) and can getIDebugSession2
from it, but itsSetException
call always gives me anHRESULT
for wrong argument, so I might be missing something here (callingSetException
on engine fromIVsLoader
gives OK, just does not work).
Is there some other approach that is better than those or have I missed something in the existing ones?
UPDATE/NOTE:
If you found this question because you want a faster "Break on All Exceptions", I have made a free extension you can get from Visual Studio Gallery: Exception Breaker.