问题
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:
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.
来源:https://stackoverflow.com/questions/9920391/script-to-enable-disable-breaking-on-specific-exception-types-in-visual-studio