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

Re: Catching exceptions thrown by an MDI Child Form separately by Andy

Andy
Mon Aug 09 17:23:35 CDT 2004

"JWA" <newsgroups@armantrout.us> wrote in message
news:Orrtf$kfEHA.3076@TK2MSFTNGP10.phx.gbl...
> 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