473,320 Members | 2,180 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

MDI Child Errors Crash Application - Unhandled Exceptions

Hi All.

I'm hoping someone can point me in the direction of a solution to unhandled
exceptions in MDI child forms causing the application to crash.

I've found various articles describing a method using Application.Run(new
MyMainParentForm) to place in the application's Sub Main to allow catching
of unhandled exceptions in the application. The problem I'm facing is that I
want to be able to trap unhandled exceptions at the MDI child form level to
allow me to clean up the child form gracefully without crashing any other
child forms that may be open, and to not then crash the application.

You can test this out by creating an MDI parent form, fire up multiple child
forms and then have a button on one of the child forms that generates an
unhandled exception. You'll find the whole app crashes.

Does anyone have a solution to this problem?

Thanks in advance,

Sam.
Nov 21 '05 #1
5 4510
I don't know I understand ur question correctly or not. but when you
close a MDI child forms by the close button, because, it will dispose
that form which with program you load it in memory and now it unloaded,
then there is no form to show again and therefore It will give u
exception
for not having this problem just add this code to the "Closing" event of
each of child page.

Me.Hide()
e.Cancel = True
I hope this solve your problem

--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
Nov 21 '05 #2
Hi

In Windows Form application, we use Application.ThreadException to handle
the Unhandled Exceptions.

Here is a KB article for your reference.
PRB: Unhandled Exceptions in Windows Form Events Are Not Propagated Up Call
Stack (324653)
http://support.microsoft.com/default...B;EN-US;324653

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #3
Sam
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
Nov 21 '05 #4
Sam
Thanks Peter, that does the trick. Any reason you know of that stops it
working when debugging?

Sam.

--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
Nov 21 '05 #5
Hi

Per the KB article, this is by design. Also you have many form(parent form,
child form, but there is only one message queue per thread. All the
unhandled exception is "eaten" by Windows Form Application Object, so we
need to use the Application.ThreadException .
CAUSE
The Microsoft .NET Framework wraps the message pump in an exception
handler. The .NET Framework only handles exceptions that reach the message
pump and that the application has not already handled. Therefore, any
unhandled exception that reaches the message pump is not propagated up the
call stack.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.

Nov 21 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Shabam | last post by:
A web application of mine developed using C# + MS SQL runs fine normally. However when I stress test it with a load testing software (using about 60 simultaneous users) some instances start...
12
by: Rakesh | last post by:
Hi, I am catching unhandled exception by attached an event handler on the Application.ThreadException event. This will ensure that I could handle all uncaught exceptions on the main thread. ...
2
by: Marty McDonald | last post by:
Many of our apps are in production and they do not have proper error logging in them - unhandled errors are seen by the users in the form of error messages and stack traces. I know how to make...
1
by: Jason Smith | last post by:
I'm rather new with vb.net and I'm having problems debugging a large vb.net application. The application is randomly crashing at two locations with "referenced memory at 0x0" violations. My...
1
by: Charles Law | last post by:
I seem to be posing a lot at the moment, so please accept my apologies. I can't say, categorically that the Infragistics tools are to blame, but I have had this intermittent problem now for two...
0
by: JWA | last post by:
Hi All, How can you capture unhandled exceptions thrown by an MDI child form separate from the entire app? I have an application-wide exception handler to catch crashes by doing the following...
11
by: Roger Vale | last post by:
Hi all Visual studio 2005 Visual Basic windows mobile application I am getting this from the imediate window A first chance exception of type 'System.InvalidCastException' occurred in...
6
by: bjornms | last post by:
The application i build in C#.net is crashing once a month. I can't reproduce the crash. Is there a way to track down where the program crashes, without putting logging everywhere in the code?...
10
by: Curious | last post by:
Hi, I've found that if I wrap my code with a try-catch block in the fashion illustrated below, it'll do what is specified in the catch section instead of crashing. Could anyone confirm that this...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.