Edit: Visual Studio 2015\'s new exception window is so much faster than the old dialog that I no longer care as much about using a keyboard shortcut for i
Well, I wrote a VS2008 C# based plug-in that toggles the 386 exceptions, and it takes about 1 second per state toggle. I'm assuming that's due to COM inter-op.
This was based on the VB/macro code in the one of your links. I could not find an easier C++ method (but not ruling it out).
The next level would be to make a plug-in that has a keyboard binding, that then opens the Exceptions UI and then "clicks" the correct tick box for you.
Good luck.
You could use a tool like AutoHotKey to create a recorded script (mouse clicks or key presses) and then assign it a hotkey that will play it back when pressed...
Very similar to the other answer, but there is a special ExceptionSetting for the group.
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
CTRL + ALT + E ALT + T Enter
works for me
My macro to ignore current CLR exception in runtime. It works like a button 'disable catching this exception type' when an exception pops at debug-time.
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
First i initalized a timer an then i call the command Exception.Debug. The timer hit, when the modal dialog is openend. If you use Win 7 with deactivated UAC SendKeys with ALT-Key will fail...i don't know why.
i played a little bit...try this (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
'...