切换“时抛出一个异常中断。”使用宏或键盘快捷键
-
12-09-2019 - |
题
编辑:的Visual Studio 2015年的新的异常窗口这么多的速度比 旧的对话,我不再关心我如何使用键盘 快捷它。
是否有宏或键盘快捷方式,将切换不使用GUI“时则抛出异常打破”?
打开使用Ctrl + Alt + E对话框,选中“公共语言运行库异常”“时抛出”框,然后点击OK是很简单的,但是这是我做了很多。我宁愿有一个快捷键这一点。
此问题是一个重复的 任何有视觉对于上处理/未处理的异常切换断裂工作室快捷/宏?
然而,海报接受的答案并没有真正的工作,我也很喜欢那个答案确实的工作。
,因为它仅切换一个特定的异常,而不是整个CLR组中的重复的问题的答案是不能接受的。
“好写一个循环,然后”。你说。但没有这么快! 有人尝试已经一>,这是无用的慢。 (是的,我已经验证了其在我的系统慢如好。)
因此,挑战是使用宏来切换整个CLR例外类别中小于1或2秒。 这个问题是一个重复 任何有视觉对于上处理/未处理的异常切换断裂工作室快捷/宏?
解决方案
我已经创建了一个免费的Visual Studio扩展,可以做到这可靠地:异常断路器。结果
它使用无证IDebugSession2.SetException
调用是非常快的:所有的异常都设置/取消所有在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
下面是布莱斯卡勒的盲目地更新,以在运行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
首先,我initalized定时器的然后我调用命令Exception.Debug。 计时器命中,当双头呆模态对话框。 如果你用Win 7 UAC停用用的SendKeys ALT-Key将失败......我不知道为什么。
我打一点点...尝试这个(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帧间运算。
此是基于在链接中的一个的VB /宏代码。我无法找到一个更简单的C ++方法(但不排除这个可能性)。
在一个新的水平将是使插件具有键盘的结合,即然后打开例外UI,然后“点击”为你正确的复选框。
好运。
您可以使用像 AutoHotkey的一个工具来创建录制的脚本(点击鼠标或按键)和然后给它分配一个热键,将回放按下时...
只是提供一些信息,我对这个发现(这里)因为我是淘净在我妄图帮助...
别人提出同样的问题,它是由张智强从MS支持回应,这里的报价响应:
恐怕宏代码不能 操作上操作 例外对话框...
要注意,这是张贴从12 2005年因此这个反应可能不再准确是非常重要的;无论哪种方式,以为我会扔在那里。
设定用于组的特殊ExceptionSetting确实切换顶层复选框的状态的建议。然而,这似乎并没有触发其下方的个别例外的树,而且,当这种引发异常,因为它的确,如果我手动检查顶级复选框我的进程不会停止。你看到不同的行为?
我的宏忽略运行时电流CLR异常。它像一个按钮“禁用捕捉该异常类型”当异常弹出在调试时。
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 输入
适用于我