开发者

Handle Debugger Events of Visual Studio 2008

I created an AddIn for Visual Studio, which should handle the case when the user debugs an application and an unhandled exception is thrown. I registered the events "OnExeceptionNotHandled" and "OnExceptionThrown" using the "Events" property of the application object. In the documentation one can read that these events get fired before the "OnEnterBreakMode". But when I debug a simple application which throws an "ArgumentException" the events do not get fired. Here's my code (shortened):

public class Connect : IDTExtensibility2
{
    public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
    {
        _applicationObject = (DTE2)application;
        _addInInstance = (AddIn)addInInst;

            _debuggerEvents = _applicationObject.Events.DebuggerEvents;
            _debuggerEvents.OnExceptionThrown += new _dispDebuggerEvents_OnExceptionThrownEventHandler(_debuggerEvents_OnExceptionThrown);
            _debuggerEvents.OnExceptionNotHandled += new _dispDebuggerEvents_OnExceptionNotHandledEventHandler(_debuggerEvents_OnExceptionNotHandled);

    }

        void _debuggerEvents_OnException开发者_Python百科NotHandled(string ExceptionType, string Name, int Code, string Description, ref dbgExceptionAction ExceptionAction)
        {
            m_panOutput.OutputString("NotHandled\n");
        }

        void _debuggerEvents_OnExceptionThrown(string ExceptionType, string Name, int Code, string Description, ref dbgExceptionAction ExceptionAction)
        {
            m_panOutput.OutputString("Thrown\n");
        }

        void _debuggerEvents_OnEnterBreakMode(dbgEventReason Reason, ref dbgExecutionAction ExecutionAction)
        {
            m_panOutput.OutputString("EnterBreakMode\n");
        }

        DebuggerEvents _debuggerEvents;

}


In my experience this event is only raised when Tools/Options/Debugging/General/Enable the exception assistant is disabled. This setting is enabled by default.


Not sure but you might need to override the methods of the base class.


I had to turn the assistant off as Frank Koch suggests: Tools/Options/Debugging/General/Enable the exception assistant is disabled.

I also hooked up the events the way this MSDN article describes:

public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
    _applicationObject = (DTE2)application;
    _addInInstance = (AddIn)addInInst;

    Globals globals;
    globals = _applicationObject.Solution.Globals; 

    _debuggerEvents = globals.DTE.Events.DebuggerEvents;

    _debuggerEvents.OnEnterBreakMode += new _dispDebuggerEvents_OnEnterBreakModeEventHandler(BreakHandler);
    _debuggerEvents.OnExceptionThrown += new _dispDebuggerEvents_OnExceptionThrownEventHandler(_debuggerEvents_OnExceptionThrown);
    _debuggerEvents.OnExceptionNotHandled += new _dispDebuggerEvents_OnExceptionNotHandledEventHandler(_debuggerEvents_OnExceptionNotHandled);

...
}


void _debuggerEvents_OnExceptionNotHandled(string ExceptionType, string Name, int Code, string Description, ref dbgExceptionAction ExceptionAction)
{
    Debug.WriteLine("NotHandled\n");
}

void _debuggerEvents_OnExceptionThrown(string ExceptionType, string Name, int Code, string Description, ref dbgExceptionAction ExceptionAction)
{
    Debug.WriteLine("Thrown\n");
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜