Script to enable/disable breaking on specific exception types in Visual Studio

江枫思渺然 提交于 2020-01-15 11:47:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!