44

編集: Visual Studio 2015 の新しい例外ウィンドウは、古いダイアログよりもはるかに高速であるため、キーボード ショートカットを使用することはあまり気にしなくなりました。

GUI を使用せずに「例外がスローされたときにブレーク」を切り替えるマクロまたはキーボード ショートカットはありますか?

ctrl+alt+e でダイアログを開き、[共通言語ランタイム例外] の [スロー] ボックスをオンにして [OK] をクリックするのは簡単ですが、これは私が頻繁に行うことです。これにはキーボードショートカットが必要です。

この質問は、 処理済み/未処理の例外でブレークを切り替えるための Visual Studio ショートカット/マクロを持っているのと同じです。

ただし、ポスターは実際には機能しない回答を受け入れました。機能する回答が本当に欲しいです。

重複した質問の回答は受け入れられません。これは、CLR グループ全体ではなく、1 つの特定の例外のみを切り替えるためです。

「では、ループを書いてください。」あなたは言う。しかし、それほど速くはありません!誰かがすでにそれを試しましたが、無駄に遅かったです。(はい、私のシステムでも遅いことを確認しました。)

したがって、課題は、マクロを使用して CLR 例外カテゴリ全体を 1 ~ 2 秒未満で切り替えることです。この質問は、 処理済み/未処理の例外でブレークを切り替えるための Visual Studio ショートカット/マクロを持っているのと同じです。

4

10 に答える 10

18

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
于 2009-06-11T14:58:37.743 に答える
14

それを確実に実行できる無料の Visual Studio 拡張機能を作成しました: Exception Breaker
非常に高速な文書化されていないIDebugSession2.SetException呼び出しを使用します。すべての例外は 20 ~ 60 ミリ秒で設定/設定解除されます。

于 2013-04-01T00:39:17.420 に答える
4

以下は、VS2010 で実行するためにやみくもに更新された Bryce Kahle の非常に便利なマクロです。

Sub ToggleExceptions()
    Dim dbg As EnvDTE100.Debugger5 = DTE.Debugger
    Dim exSettings As ExceptionSettings = dbg.ExceptionGroups.Item("Common Language Runtime Exceptions")
    Dim exSetting As 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

End Sub
于 2010-04-19T20:26:20.330 に答える
2

最初にタイマーを初期化し、コマンド Exception.Debug を呼び出します。モーダル ダイアログが開いているときにタイマーがヒットしました。非アクティブ化されたUAC SendKeysでALTキーを使用してWin 7を使用すると失敗します...理由はわかりません。

私は少しプレイしました...これを試してください(VS2010 EN):

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics
Imports System.Runtime.InteropServices

'...

Private WithEvents t As Timers.Timer
Private Sub t_Elapsed(ByVal ee As Object, ByVal dd As Timers.ElapsedEventArgs) Handles t.Elapsed
    t.Stop()
    ' Tastatureingaben simulieren
    System.Windows.Forms.SendKeys.SendWait("{DOWN}")
    System.Threading.Thread.Sleep(1500) ' Pause wichtig zum Laden des Exceptionbaums
    System.Windows.Forms.SendKeys.SendWait("%t")
    System.Windows.Forms.SendKeys.SendWait("{ENTER}")
End Sub
Public Sub toggleCLRExceptions()
    If DTE.Solution.Count <= 0 Then
        MsgBox("Nicht ohne geöffnete Solution!")
        Exit Sub
    End If
    ' Timer wird benötigt, da der Dialog Modal ist
    ' und weitere Befehle im Macro werden erst nach beenden des Dialogs ausgeführt
    t = New Timers.Timer()
    t.Interval = 0.5
    t.Start()
    DTE.ExecuteCommand("Debug.Exceptions")
    'System.Windows.Forms.SendKeys.SendWait("^%e") ' alternativ: STRG+ALT+e
    System.Threading.Thread.Sleep(200)
    If isCLRExceptionsActive() Then
        MsgBox("BREAK @CLR-Exception", MsgBoxStyle.Information, "Info")
    Else
        MsgBox("NO BREAK @CLR-Exception", MsgBoxStyle.Information, "Info")
    End If
End Sub

Function isCLRExceptionsActive() As Boolean
    ' prüft, ob Setting Debug CLR-Exceptions aktiviert/deaktivert ist
    Dim dbg As EnvDTE100.Debugger5 = DTE.Debugger
    Dim exSettings As ExceptionSettings = dbg.ExceptionGroups.Item("Common Language Runtime Exceptions")
    Dim exSetting As 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
    Return exSetting.BreakWhenThrown
End Function

'...
于 2011-10-26T13:12:36.417 に答える
1

実行時に現在の CLR 例外を無視するマクロ。デバッグ時に例外が発生すると、「この例外タイプのキャッチを無効にする」ボタンのように機能します。

Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports EnvDTE90a
Imports EnvDTE100
Imports System.Diagnostics
Imports Microsoft.VisualBasic
Imports Microsoft.VisualBasic.ControlChars

' execute Macros.MyMacros.VSDebuggerExceptions.IgnoreCurrentExceptionWhenThrown from VS Command Window

Public Module VSDebuggerExceptions

    Sub BreakWhenThrown(Optional ByVal strException As String = "")
        Dim dbg As Debugger3 = DTE.Debugger
        Dim eg As ExceptionSettings = _
            dbg.ExceptionGroups.Item("Common Language Runtime Exceptions")
        eg.SetBreakWhenThrown(True, eg.Item(strException))
    End Sub

    ' copied from Utilities module (samples)
    Function GetOutputWindowPane(ByVal Name As String, Optional ByVal show As Boolean = True) As OutputWindowPane
        Dim window As Window
        Dim outputWindow As OutputWindow
        Dim outputWindowPane As OutputWindowPane

        window = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindOutput)
        If show Then window.Visible = True
        outputWindow = window.Object
        Try
            outputWindowPane = outputWindow.OutputWindowPanes.Item(Name)
        Catch e As System.Exception
            outputWindowPane = outputWindow.OutputWindowPanes.Add(Name)
        End Try
        outputWindowPane.Activate()
        Return outputWindowPane
    End Function

    Private WithEvents t As Timers.Timer

    ' Adds the current exception to ignore list
    Sub IgnoreCurrentExceptionWhenThrown()
        Dim commandWin As EnvDTE.CommandWindow
        commandWin = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindCommandWindow).Object

        Select Case DTE.Debugger.CurrentMode
            Case dbgDebugMode.dbgDesignMode
                commandWin.OutputString("This macro is not enabled in Design Mode. Run it in Break Mode." + vbCrLf)
                Return

            Case dbgDebugMode.dbgRunMode
                commandWin.OutputString("This macro is not enabled in Run Mode. Run it in Break Mode." + vbCrLf)
                Return
        End Select

        commandWin.OutputString(Environment.NewLine)
        commandWin.OutputString("Trying to get the information about current exception.." + Environment.NewLine)

        Dim dbg As Debugger3 = DTE.Debugger
        Dim currentExpression As Expression = dbg.GetExpression("$exception", False)
        Try    
            Dim currentExceptionTypeString As String = currentExpression.DataMembers.Item(1).Type
            commandWin.OutputString("Detected current exception type is : " + currentExceptionTypeString + Environment.NewLine)

            Dim flag As Boolean = True
            Dim eg As ExceptionSettings = dbg.ExceptionGroups.Item("Common Language Runtime Exceptions")
            Try
                eg.SetBreakWhenThrown(False, eg.Item(currentExceptionTypeString))
            Catch exc As Exception
                commandWin.OutputString("Cannot find this exception, trying to create.." + currentExceptionTypeString + Environment.NewLine)
                '
                eg.NewException(currentExceptionTypeString, New Random().Next)
                eg.SetBreakWhenThrown(False, eg.Item(currentExceptionTypeString))
                eg.SetBreakWhenUserUnhandled(True, eg.Item(currentExceptionTypeString))
                flag = False
            End Try

            commandWin.OutputString(Environment.NewLine)
            commandWin.OutputString("Exception '" + currentExceptionTypeString + "' added to ignore list.")
            commandWin.OutputString(Environment.NewLine)

            t = New Timers.Timer()
            ' small interval to send keys after DTE will start to exec command
            t.Interval = 0.1
            t.Start()
            DTE.ExecuteCommand("Debug.Exceptions")

        Catch exc As Exception
            commandWin.OutputString("Error occured")
        End Try
    End Sub

    Private Sub t_Elapsed(ByVal ee As Object, ByVal dd As Timers.ElapsedEventArgs) Handles t.Elapsed
        t.Stop()
        ' only press Ok to apply changed exceptions settings to debugger
        System.Windows.Forms.SendKeys.SendWait("%t")
        System.Windows.Forms.SendKeys.SendWait("{ENTER}")
    End Sub

End Module
于 2012-01-25T11:18:06.937 に答える
1

CTRL + ALT + E ALT + T エンター

私のために働く

于 2013-08-12T15:50:57.637 に答える
1

私がこれで見つけたいくつかの情報を提供するだけです(ここ)、役に立たない無駄な試みでネットを精査していた...

他の誰かがこの同じ質問を提起し、MS サポートの Gary Chang によって回答されました。引用された回答は次のとおりです。

残念ながら、マクロ コードは [例外] ダイアログ ボックスの操作を操作できません...

この投稿は 2005 年 12 月のものであるため、この回答は正確ではない可能性があることに注意してください。いずれにせよ、私はそれをそこに捨てると思った。

于 2009-06-17T12:29:22.700 に答える
1

さて、私は 386 例外を切り替える VS2008 C# ベースのプラグインを作成しました。状態の切り替えごとに約 1 秒かかります。これは COM の相互運用によるものだと思います。

これは、リンクの 1 つの VB/マクロ コードに基づいていました。もっと簡単な C++ メソッドを見つけることができませんでした (ただし、除外はしませんでした)。

次のレベルでは、キーボード バインディングを備えたプラグインを作成し、例外 UI を開き、正しいチェック ボックスを「クリック」します。

幸運を。

于 2009-06-11T09:38:27.260 に答える
1

AutoHotKeyのようなツールを使用して、記録されたスクリプト (マウスのクリックまたはキーの押下) を作成し、押されたときにそれを再生するホットキーを割り当てることができます...

于 2009-06-17T05:14:45.643 に答える