2016-11-14 34 views
0

現在Visual Studio 2015をインストールしているため、IDEからコードを実行中に未処理の例外がスローされることはありません。未処理の例外処理をデバッグする方法

Private Sub btnTest_Click(sender As System.Object, e As System.EventArgs) Handles btnTest.Click 
    Throw New System.Exception("An unhandled test exception has occurred.") 
End Sub 

のみコードをIDEで実行されていない場合は、通常の実行時に動作します:私は私の未処理の例外コードが、私のコードを行使したいです。

未処理の例外コードをIDEでどのようにデバッグできますか?

私はDebug、Windows、例外設定を見ましたが、私は何をしたいのかわかりません。 IDEが例外をキャプチャせずに未処理の例外を許可するもう一つのグローバル設定がありますか?


私は、イベントをフックするApplicationsEvents.vbを使用しています:

Namespace My 

' The following events are available for MyApplication: 
' 
' Startup: Raised when the application starts, before the startup form is created. 
' Shutdown: Raised after all application forms are closed. This event is not raised if the application terminates abnormally. 
' UnhandledException: Raised if the application encounters an unhandled exception. 
' StartupNextInstance: Raised when launching a single-instance application and the application is already active. 
' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected. 
Partial Friend Class MyApplication 
    Private Sub MyApplication_UnhandledException(sender As Object, e As Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventArgs) Handles Me.UnhandledException 
     ExpLog.LogUnhandledException(e, sender) 
     e.ExitApplication = Not ExpLog.InformUser 
    End Sub 
End Class 
End Namespace 

決議は、ハンドラによって呼び出されたコードを行使し、テストスタブを作成することでした

Private Sub Button6_Click(sender As System.Object, e As System.EventArgs) Handles btnMisc_Throw.Click 

    If ExpLog.InformUser() Then 
     MsgBox("Continue") 
    Else 
     MsgBox("End Program") 
    End If 

    ExpLog.LogMsgBox(New System.Exception("test unhandled exception"), "test LogMsgBox()",,, "programmer note") 

End Sub 

これはハンドラのテストを許可しませんが、ハンドラが呼び出すコードを実行します。私は5 +年前にこれを考え出した... :(

+0

にハンドラを追加する。 – rheitzman

+0

した後、いくつかの古いコメントを見てみます私はあなたのコードを試して、それが動作しないことを確認します。可能であれば、私がやったやり方を試してみてください。 – djv

+0

私はMDIコンテナ(フォームレベル)からテスト例外を投げてみました。 )あなたの方法はスタンドアロン形式で作業しましたが、私はスタンドアロンとMDI-Child形式が混在しているので、アプリケーションレベルで未処理のイベントをキャプチャする必要があります。 – rheitzman

答えて

0

マイ `bntTest_Click`コードは、MDI親フォーム内の子フォーム上にあるAppDomain.CurrentDomain.UnhandledException

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load 
    AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf UnhandledExceptionHandler 
End Sub 

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 
    Throw New System.Exception("An unhandled test exception has occurred.") 
End Sub 

Public Shared Sub UnhandledExceptionHandler(ByVal sender As Object, ByVal args As UnhandledExceptionEventArgs) 
    MessageBox.Show(CType(args.ExceptionObject, Exception).Message) 
End Sub 
+0

私は、exeがIDEの外で実行されるときに動作するハンドラを持っています。 IDEからハンドラをデバッグしようとしています。ポストのように未処理の例外をスローすると、IDEが停止してハンドラを起動しません。 – rheitzman

+0

奇妙なことに、私のIDEはハンドラ*を起動し、例外時には停止します。 Win7x64 VS2012 v4.6を実行すると、私の経験は、http://stackoverflow.com/questions/406385/handling-unhandled-exceptions-problemで嫌に思われる – djv

+0

私は違いがC#vs VB.netとVBアプリケーションイベント機能かもしれないと思うVisual Studioの私はこのイベントを1度にデバッグできると思っていたので、2012年と2015年の両方が可能です。 – rheitzman