Ich habe ein untergeordnetes Formular, das eine ApplicationException in den Load-Ereignishandler wirft (absichtlich zu Testzwecken). Das übergeordnete Formular umschließt die ChildForm.Show() - Methode in einem Try ... Catch ex As Exception-Block. Der catch-Block zeigt einfach eine Nachricht an und schließt das untergeordnete Formular. Alles funktioniert wie erwartet, wenn in Visual Studio 2008 (. Net 3.5 SP1) debuggt. Wenn ich es jedoch außerhalb von Visual Studio ausführe, scheint der Catch-Block verpasst zu werden und eine nicht behandelte Ausnahme tritt auf. Irgendeine Idee warum das ist?Catch-Block nicht abfangen
Vielen Dank.
Beispielcode:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim f2 As Form2
f2 = New Form2
Try
MessageBox.Show("Opening form 2")
f2.ShowDialog()
Catch ex As Exception
f2.Close()
MessageBox.Show("Form 2 closed.")
End Try
End Sub
End Class
Public Class Form2
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Throw New ApplicationException("Test Form_Load")
End Sub
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
End Sub
End Class
Stack Trace:
System.ApplicationException: Test Form_Load at WindowsApplication1.Form2.Form2_Load(Object sender, EventArgs e) in UnhandledExceptionTest2\WindowsApplication1\Form2.vb System.Windows.Forms.Form.OnLoad(EventArgs e) System.Windows.Forms.Form.OnCreateControl() System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) System.Windows.Forms.Control.CreateControl() System.Windows.Forms.Control.WmShowWindow(Message& m) at System.Windows.Forms.Control.WndProc(Message&> m) at System.Windows.Forms.ScrollableControl.WndProc(Message&> m) at System.Windows.Forms.ContainerControl.WndProc(Message&> m) at System.Windows.Forms.Form.WmShowWindow(Message&> m) at System.Windows.Forms.Form.WndProc(Message&> m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&> m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&> m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Können Sie etwas Code posten? –
Ja - es ist vage wie beschrieben ... –