处理 Visual Studio 2008 的调试器事件
我为 Visual Studio 创建了一个 AddIn,它应该处理用户调试应用程序并引发未处理的异常时的情况。我使用应用程序对象的“Events”属性注册了事件“OnExeceptionNotHandled”和“OnExceptionThrown”。在文档中可以看到这些事件在“OnEnterBreakMode”之前被触发。但是,当我调试一个引发“ArgumentException”的简单应用程序时,事件不会被触发。这是我的代码(缩短):
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;
}
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_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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据我的经验,仅当禁用
Tools/Options/Debugging/General/Enable the exception Assistant
时,才会引发此事件。默认情况下启用此设置。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.
我必须按照 Frank Koch 的建议关闭助手:
工具/选项/调试/常规/启用异常
助手被禁用。我还按照这篇 MSDN 文章描述的方式连接了这些事件:
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: