Script to enable/disable breaking on specific exce

2019-08-10 11:02发布

I currently use the Debug -> Exceptions dialog to stop VS from breaking for certain exceptions types. This works perfectly. The problem comes in that occasionally I would like to debug those exceptions, or accidentally turn all exceptions on or off, I then have to hunt through the list and disable the specific exceptions from scratch.

Is there a way to do this with a script of some sort? So that I can add whichever options to a list and toggle then on or off easily?

1条回答
何必那么认真
2楼-- · 2019-08-10 11:45

You can write a macro that uses the EnvDTE.Debugger3 interface. This sample one turns on the break for a NullReferenceException, written out to make the intermediate steps obvious:

Sub SetNullReferenceExceptionTrap()
    Dim dbg As Debugger3 = DTE.Debugger
    Dim group As ExceptionSettings = dbg.ExceptionGroups.Item("Common Language Runtime Exceptions")
    Dim except As ExceptionSetting = group.Item(GetType(System.NullReferenceException).FullName)
    group.SetBreakWhenThrown(True, except)
End Sub

To turn it off, pass False as the first argument.

查看更多
登录 后发表回答