2010-01-01 7 views
1

J'ai créé un AddIn pour Visual Studio, qui doit gérer le cas lorsque l'utilisateur débogue une application et qu'une exception non gérée est levée. J'ai enregistré les événements "OnExeceptionNotHandled" et "OnExceptionThrown" en utilisant la propriété "Events" de l'objet d'application. Dans la documentation on peut lire que ces événements se déclenchent avant le "OnEnterBreakMode". Mais quand je débogue une application simple qui lance une "ArgumentException" les événements ne sont pas déclenchés. Voici mon code (raccourci):Gestion des événements du débogueur de Visual Studio 2008

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_OnExceptionNotHandled(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; 

} 
+0

Je vais avoir exactement le même problème, je ne peux pas obtenir les événements à l'incendie soit :( –

Répondre

0

Vous ne savez pas, mais vous devrez peut-être remplacer les méthodes de la classe de base.

1

Dans mon expérience, cet événement est levé uniquement lorsque Tools/Options/Debugging/General/Enable the exception assistant est désactivé. Ce paramètre est activé par défaut.

0

J'ai dû désactiver l'assistant comme le suggère Frank Koch: L'assistant Tools/Options/Debugging/General/Enable the exception est désactivé.

J'ai aussi accroché les événements de la façon 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"); 
} 
Questions connexes