Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
567 views
in Technique[技术] by (71.8m points)

visual studio - Toggle "Break when an exception is thrown." using macro or keyboard shortcut

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 it.

Is there a macro or keyboard shortcut that will toggle "break when an exception is thrown" without using the GUI?

Opening the dialog with ctrl+alt+e and checking the "Common Language Runtime Exceptions" "Thrown" box then clicking OK is simple enough, but this is something I do a lot. I would rather have a keyboard shortcut for this.

This question is a duplicate of Any have a Visual Studio shortcut/macro for toggling break on handled/unhandled exceptions?

However, the poster accepted an answer that doesn't really work, and I would really like an answer that does work.

The answer in the duplicate question is not acceptable because it toggles only one specific exception, not the entire CLR group.

"Well write a loop then." you say. But not so fast! Someone tried that already and it was uselessly slow. (Yes I've verified that its slow on my system as well.)

So the challenge is to use a macro to toggle the entire CLR Exceptions category in less than 1 or 2 seconds. This question is a duplicate of Any have a Visual Studio shortcut/macro for toggling break on handled/unhandled exceptions?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...