Visual Studio Developer Center > Visual Studio Forums > Visual Studio Debugger > Setting exceptions to break on when thrown with a macro

Unanswered Setting exceptions to break on when thrown with a macro

  • Saturday, February 23, 2008 5:57 PM
     
     

    Does anyone know if there is a way to set the exceptions to break on when thrown with a marco. I either want them all off or all but two on and would like to be able to do this with out having to navigate through the dialog.

     

    Thanks

All Replies

  • Monday, February 25, 2008 8:42 PM
    Moderator
     
     
    This can be done in VS 2008:

     

    Sub Macro1()

    Dim debugger As Debugger3 = DTE.Debugger

    Dim clrGroup = debugger.ExceptionGroups.Item("Common Language Runtime Exceptions")

    Dim nullRef = clrGroup.Item("System.NullReferenceException")

    clrGroup.SetBreakWhenThrown(True, nullRef)

    End Sub

    • Unmarked As Answer by dougzhoez Sunday, August 03, 2008 5:40 AM
    •  
  • Tuesday, February 26, 2008 12:07 AM
     
     

    Thank you. I am using VS 2005 though so I guess I can't.

  • Sunday, August 03, 2008 5:40 AM
     
     
    Ok, now I have VS 2008. Is there any way to set BreakWhenThrown to true for all the exceptions in the "Common Language Runtime Exceptions" that is actually faster than doing it manually? Calling SetBreakWhenThrown for all of them takes longer than 10 minutes (I'm not patient enough to find out exactly how long it takes). This makes the "feature" useless.

    Sub TurnOnBreakWhenThrown()
            Dim debugger As Debugger3 = DTE.Debugger
            Dim clrGroup = debugger.ExceptionGroups.Item("Common Language Runtime Exceptions")

            'turn on break when thrown for all ExceptionSettings in "Common Language Runtime Exceptions"
            For Each expressionSetting As ExceptionSetting In clrGroup
                If (expressionSetting.BreakWhenThrown() = False) Then
                    clrGroup.SetBreakWhenThrown(True, expressionSetting)
                End If
            Next
    End Sub

  • Tuesday, October 27, 2009 2:07 PM
     
     
    A similar question was posted and answered at http://stackoverflow.com/questions/958011/toggle-break-when-an-exception-is-thrown-using-macro-or-keyboard-shortcut. It works for all CLR exceptions and takes ~1.5s to execute.