我当前安装的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中调试未处理的异常代码?
我看着调试,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
这不允许测试处理程序,但它会执行处理程序调用的代码。看着一些老的意见自从五+年前想通了这一点... :(
我'bntTest_Click'代码是一个MDI父窗体中子窗体上。 – rheitzman
后看到你在ApplicationEvents中的编辑,这与我添加处理程序的方式不一样。我尝试了你的代码并确认它不起作用。尝试我尽可能的方式。 – djv
我尝试从MDI容器中引发测试异常(表单级别)并且它也失败了,你的方法是以独立的形式工作,但是我需要在应用程序级别捕获未处理的事件,因为我有独立和MDI-Child形式的混合。 – rheitzman