Throw exception means ShowDialog doesn't halt execution.

D

David Brunning

I have an application running on PocketPC which is controlled by a
while loop - child forms are opened using Reflection and before they
close raise an event to set the type of the next form to open. The
code for this control stuff is attached below.

In the child form that is opened if I raise an exception (After form
load as finished, i.e. wire up a button to an event handler and in
that handler throw a System.Exception.) this is correctly caught by
the code below but code execution doesn't stop on the ShowDialog()
line, instead the form which i am opening to report the exception is
being disposed immediately so that the user never sees it.

Any ideas?

/*CONTROL CODE SAMPLE*/
System.Windows.Forms.Form CurrentForm;
this.mNextFormType=typeof(Form1);

while (this.mNextFormType!=null)
{
try
{
//Open a form if there is a type specified.
CurrentForm=(System.Windows.Forms.Form)Activator.CreateInstance(this.mNextFormType);
this.mNextFormType=null;
CurrentForm.ShowDialog();
CurrentForm.Dispose();
}
catch (Exception exc)
{
//Display exception details
TestException TempForm=new TestException();
//Forms.ExceptionReport TempForm=new
CCSIT.KeystoneMobile.Forms.ExceptionReport(exc);
TempForm.Enabled=true;
TempForm.ShowDialog();
TempForm.Dispose();
}
}
 
D

David Brunning

It looks as if raising an exception across form boundaries doesn't
work in the compact framework - thinking about it this probably isn't
a great idea anyway.

I am maintaining state using a statemanager class and now raise an
event on that if there is an exception which is raised in the child
form (Adding exception handlers to all event handlers in the child
form so that an exception is never raised unhandled) which allows me
to handle the exception at the top level in the application and
display my exception report form.

This works fine.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top