使用macros或键盘快捷键切换“抛出exception时中断”

编辑:Visual Studio 2015的新的exception窗口比旧的对话快得多,我不再关心使用键盘快捷键。

是否有一个macros或键盘快捷方式,将切换“引发exception时中断”,而不使用GUI?

用ctrl + alt + e打开对话框并选中“Common Language Runtime Exceptions”“Thrown”框,然后点击OK就足够简单了,但这是我做的很多事情。 我宁愿有一个键盘快捷键。

这个问题是重复的任何有一个Visual Studio快捷方式/macros切换处理/未处理的exception中断?

然而,海报接受了一个并不真正起作用的答案,我真的很想有一个可行的答案。

重复问题中的答案是不可接受的,因为它只切换一个特定的exception,而不是整个CLR组。

“那就写一个循环吧。” 你说。 但不是那么快! 有人已经试过了 ,而且是无用的慢。 (是的,我已经validation了它在我的系统上也很慢。)

所以面临的挑战是使用macros在不到1或2秒的时间内切换整个CLRexception类别。 这个问题是重复的任何有一个Visual Studio快捷方式/macros切换处理/未处理的exception中断?

我创build了一个免费的Visual Studio扩展,可以做到这一点可靠: 例外破坏者 。
它使用非常快速的未logging的IDebugSession2.SetException调用:所有exception都在20到60毫秒内设置/取消设置。

与其他答案非常相似,但是该组有一个特殊的ExceptionSetting。

 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 

这里是Bryce Kahle非常有用的macros观更新,在VS2010中运行:

 Sub ToggleExceptions() Dim dbg As EnvDTE100.Debugger5 = DTE.Debugger Dim exSettings As ExceptionSettings = dbg.ExceptionGroups.Item("Common Language Runtime Exceptions") Dim exSetting As 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 End Sub 

首先,我使用了一个定时器,然后我调用Exception.Debug命令。 当模式对话框打开时,计时器命中。 如果您使用Win 7与取消激活UAC SendKeys ALT键将失败…我不知道为什么。

我玩了一点点…试试这个(VS2010 EN):

 Imports System Imports EnvDTE Imports EnvDTE80 Imports EnvDTE90 Imports EnvDTE90a Imports EnvDTE100 Imports System.Diagnostics Imports System.Runtime.InteropServices '... Private WithEvents t As Timers.Timer Private Sub t_Elapsed(ByVal ee As Object, ByVal dd As Timers.ElapsedEventArgs) Handles t.Elapsed t.Stop() ' Tastatureingaben simulieren System.Windows.Forms.SendKeys.SendWait("{DOWN}") System.Threading.Thread.Sleep(1500) ' Pause wichtig zum Laden des Exceptionbaums System.Windows.Forms.SendKeys.SendWait("%t") System.Windows.Forms.SendKeys.SendWait("{ENTER}") End Sub Public Sub toggleCLRExceptions() If DTE.Solution.Count <= 0 Then MsgBox("Nicht ohne geöffnete Solution!") Exit Sub End If ' Timer wird benötigt, da der Dialog Modal ist ' und weitere Befehle im Macro werden erst nach beenden des Dialogs ausgeführt t = New Timers.Timer() t.Interval = 0.5 t.Start() DTE.ExecuteCommand("Debug.Exceptions") 'System.Windows.Forms.SendKeys.SendWait("^%e") ' alternativ: STRG+ALT+e System.Threading.Thread.Sleep(200) If isCLRExceptionsActive() Then MsgBox("BREAK @CLR-Exception", MsgBoxStyle.Information, "Info") Else MsgBox("NO BREAK @CLR-Exception", MsgBoxStyle.Information, "Info") End If End Sub Function isCLRExceptionsActive() As Boolean ' prüft, ob Setting Debug CLR-Exceptions aktiviert/deaktivert ist Dim dbg As EnvDTE100.Debugger5 = DTE.Debugger Dim exSettings As ExceptionSettings = dbg.ExceptionGroups.Item("Common Language Runtime Exceptions") Dim exSetting As 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 Return exSetting.BreakWhenThrown End Function '... 

那么,我写了一个基于VS2008 C#的插件,切换386例外,每个状态切换大约需要1秒。 我假设这是由于COM inter-op。

这是基于你的链接中的VB /macros代码。 我找不到更简单的C ++方法(但不排除)。

下一个级别是创build一个具有键盘绑定的插件,然后打开Exceptions UI,然后为您“点击”正确的checkbox。

祝你好运。

你可以使用像AutoHotKey这样的工具来创build一个录制的脚本(鼠标点击或按键),然后分配一个热键,当按下时会回放…

只是提供了一些信息,我发现这里( 这里 ),因为我在网上search我徒劳无益的帮助…

其他人提出了同样的问题,并由MS Support的Gary Chang回复,引用的回复如下:

我恐怕macros代码不能操作例外对话框上的操作…

重要的是要注意,这个post是从2005年12月,所以这个回应可能不再准确; 不pipe怎样,我想我会把它扔在那里。

为组设置特殊的ExceptionSetting的build议的确切换了顶层checkbox的状态。 但是,它似乎并没有在树中切换到它下面的单个exception,而且,当我手动检查顶层checkbox时,我的进程不会停止,因为这样会引发exception。 你看到不同的行为?

我的macros在运行时忽略当前的CLRexception。 当debugging时popup一个exception,它就像一个button'禁用捕获这个exceptiontypes'。

 Imports System Imports EnvDTE Imports EnvDTE80 Imports EnvDTE90 Imports EnvDTE90a Imports EnvDTE100 Imports System.Diagnostics Imports Microsoft.VisualBasic Imports Microsoft.VisualBasic.ControlChars ' execute Macros.MyMacros.VSDebuggerExceptions.IgnoreCurrentExceptionWhenThrown from VS Command Window Public Module VSDebuggerExceptions Sub BreakWhenThrown(Optional ByVal strException As String = "") Dim dbg As Debugger3 = DTE.Debugger Dim eg As ExceptionSettings = _ dbg.ExceptionGroups.Item("Common Language Runtime Exceptions") eg.SetBreakWhenThrown(True, eg.Item(strException)) End Sub ' copied from Utilities module (samples) Function GetOutputWindowPane(ByVal Name As String, Optional ByVal show As Boolean = True) As OutputWindowPane Dim window As Window Dim outputWindow As OutputWindow Dim outputWindowPane As OutputWindowPane window = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindOutput) If show Then window.Visible = True outputWindow = window.Object Try outputWindowPane = outputWindow.OutputWindowPanes.Item(Name) Catch e As System.Exception outputWindowPane = outputWindow.OutputWindowPanes.Add(Name) End Try outputWindowPane.Activate() Return outputWindowPane End Function Private WithEvents t As Timers.Timer ' Adds the current exception to ignore list Sub IgnoreCurrentExceptionWhenThrown() Dim commandWin As EnvDTE.CommandWindow commandWin = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindCommandWindow).Object Select Case DTE.Debugger.CurrentMode Case dbgDebugMode.dbgDesignMode commandWin.OutputString("This macro is not enabled in Design Mode. Run it in Break Mode." + vbCrLf) Return Case dbgDebugMode.dbgRunMode commandWin.OutputString("This macro is not enabled in Run Mode. Run it in Break Mode." + vbCrLf) Return End Select commandWin.OutputString(Environment.NewLine) commandWin.OutputString("Trying to get the information about current exception.." + Environment.NewLine) Dim dbg As Debugger3 = DTE.Debugger Dim currentExpression As Expression = dbg.GetExpression("$exception", False) Try Dim currentExceptionTypeString As String = currentExpression.DataMembers.Item(1).Type commandWin.OutputString("Detected current exception type is : " + currentExceptionTypeString + Environment.NewLine) Dim flag As Boolean = True Dim eg As ExceptionSettings = dbg.ExceptionGroups.Item("Common Language Runtime Exceptions") Try eg.SetBreakWhenThrown(False, eg.Item(currentExceptionTypeString)) Catch exc As Exception commandWin.OutputString("Cannot find this exception, trying to create.." + currentExceptionTypeString + Environment.NewLine) ' eg.NewException(currentExceptionTypeString, New Random().Next) eg.SetBreakWhenThrown(False, eg.Item(currentExceptionTypeString)) eg.SetBreakWhenUserUnhandled(True, eg.Item(currentExceptionTypeString)) flag = False End Try commandWin.OutputString(Environment.NewLine) commandWin.OutputString("Exception '" + currentExceptionTypeString + "' added to ignore list.") commandWin.OutputString(Environment.NewLine) t = New Timers.Timer() ' small interval to send keys after DTE will start to exec command t.Interval = 0.1 t.Start() DTE.ExecuteCommand("Debug.Exceptions") Catch exc As Exception commandWin.OutputString("Error occured") End Try End Sub Private Sub t_Elapsed(ByVal ee As Object, ByVal dd As Timers.ElapsedEventArgs) Handles t.Elapsed t.Stop() ' only press Ok to apply changed exceptions settings to debugger System.Windows.Forms.SendKeys.SendWait("%t") System.Windows.Forms.SendKeys.SendWait("{ENTER}") End Sub End Module 

CTRL + ALT + E ALT + T Enter

为我工作