目前,如果我想告诉 Visual Studio 2010 在出现异常时停止,我必须转到 Debug/Exceptions... 菜单(或 Ctrl+Alt+E)并单击 CLR Exceptions 下的 Throw 复选框。这是一个耗时的过程,特别是如果我需要定期切换这些。

有没有更快的方法来切换这个功能?也许使用键盘快捷键。

最佳答案

使用这样的东西:

Dim dbg As EnvDTE90.Debugger3 = DTE.Debugger
Dim exSettings As EnvDTE90.ExceptionSettings = dbg.ExceptionGroups.Item("Common Language Runtime Exceptions")
Dim exSetting As EnvDTE90.ExceptionSetting
Try
    exSetting = exSettings.Item("Common Language Runtime Exceptions")
Catch ex As COMException
    If ex.ErrorCode = -2147352565 Then
        exSetting = exSettings.NewException("Common Language Runtime Exceptions", 0)
    End If
End Try

If exSetting.BreakWhenThrown Then
    exSettings.SetBreakWhenThrown(False, exSetting)
Else
    exSettings.SetBreakWhenThrown(True, exSetting)
End If

它将成功选中“异常(exception)”对话框中的顶级复选框。

10-07 20:29