Hi Sara.
I'm not talking about the standard way of closing a form, but the way an
MDI application will crash if an unhandled exception occurs in an MDI
child.
To test the behaviour:
1) Create a new Visual Basic Windows Application
2) Add a new module called "MainModule" with the following code (you may
need to reformat the code after pasting into the code window) ...
Imports System
Imports System.Windows.Forms
Module MainModule
Sub Main()
Try
' Start the application using a new instance of the MDI parent
form
Application.Run(New MdiParentForm)
Catch ex As Exception
' Display exception
MessageBox.Show(String.Format("The whole application has crashed
with the following error details:{0}{0}{1}", Environment.NewLine,
ex.ToString()), "Terminal Application Exception", MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
End Module
3) Add a new form called "MdiParentForm"
4) Set the "IsMdiContainer" property of MdiParentForm to "True"
5) Paste the following code in the Form's Load event:
' Initialise multiple child forms
For count As Integer = 0 To 3
Dim child As New MdiChildForm
child.MdiParent = Me
child.Show()
Next
6) Add another form called "MdiChildForm"
7) Add a button to MdiChildForm form called "CauseExceptionButton"
8) Place the following code in the Click event of CauseExceptionButton:
Throw New Exception("This is a crash test")
9) Set the startup object of the project to be "MainModule"
10) Run the project.
You should see MdiParentForm with multiple child windows. Click on the
button inside one of the child windows to cause an unhandled exception.
Watch the whole app crash.
Can anyone tell me how to isolate the unhandled exception in the child
form that caused it without crashing the whole application?
Cheers,
Sam.
--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com