Catching exceptions thrown by an MDI Child Form separately

J

JWA

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 in my Application entry point:

Public Shared Sub Main()
'Explicitly set apartment state to Single Thread Apartment (STA)
System.Threading.Thread.CurrentThread.ApartmentState =
System.Threading.ApartmentState.STA
Dim eh As New MyExceptionHandler()
AddHandler Application.ThreadException, AddressOf
eh.OnThreadException
Application.Run(New Form1)
End Sub

The form that I'm using to handle this reports/logs the exception and
closes down the application. This works perfectly. I now want to enhance
this functionality by catching unhandled exceptions within individual
MDI Child forms so that I can close down just the child form and not the
entire app. I'm having trouble isolating the exceptions thrown by the
child forms separately. Does anyone have any tips on how best to do this?

Thanks,

--Josh
 
A

Andy Becker

JWA said:
This works perfectly. I now want to enhance
this functionality by catching unhandled exceptions within individual
MDI Child forms so that I can close down just the child form and not the
entire app. I'm having trouble isolating the exceptions thrown by the
child forms separately. Does anyone have any tips on how best to do this?

Thanks,

--Josh

Difficult when all are the same thread...

Perhaps your current global exception handler can examine
Form1.ActiveMDIChild? If it has a value, then theoretically the problem
came from an MDI child. I guess this would depend on how much other code is
in your main form, which can be called while a child form is open.

I suspect there are better ways though.

Best Regards,

Andy
 

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