2016-11-14 3 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, Exception Settings에서 보았지만 내가하고 싶은 일을 할 수있는 방법이 없습니다. IDE에서 예외를 캡처하지 않고 처리되지 않은 예외를 허용하는 또 다른 전역 설정이 있습니까? 핸들러에 의해 호출 된 코드를 행사 테스트 스텁을 만들

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 

해결이되었다 :


나는 이벤트를 후크하는 ApplicationsEvents.vb을 사용하고

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 

이렇게하면 처리기를 테스트 할 수 없지만 처리기에서 호출하는 코드는 실행됩니다. 오래된 의견을 보면 나는 다섯 + 년 전을 생각 ... :(

+0

내'bntTest_Click' 코드가 MDI 부모 폼 내부에 자식 폼에에 핸들러를 추가합니다. – rheitzman

+0

을 한 후 ApplicationEvents에서 편집을 보았습니다. 이것은 처리기를 추가 한 것과는 다릅니다. 코드를 시도하고 작동하지 않는지 확인하십시오. 가능한 경우 수행 한 방법을 시도하십시오. – djv

+0

MDI 컨테이너 (폼 수준) 당신의 방법은 독립형에서 작동하지만 독립형 및 MDI-Child 형식이 혼합되어 있으므로 응용 프로그램 수준에서 처리되지 않은 이벤트를 캡처해야합니다. – rheitzman

답변

0

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 Application Events 기능 일 것 같습니다. Visual Studio. 내가이 이벤트를 한 번에 디버그 할 수 있다고 생각 했으므로 2012 년 대 2015 년이 될 수 있습니다. – rheitzman