473,503 Members | 12,103 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Tricky exception trapping question

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.ApartmentSta te = 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
Jul 21 '05 #1
3 1404
There's no mechanism that allows you to add an unhandled exception handler
on a per-mdi child basis. You should also be aware that the
Application.ThreadException event will not be generated if the exception
occurs on any other thread then the one the winform itself is executing on.

If you want to catch all exceptions that can occur in the app regardless of
the thread it occurs on you should subscribe to the
AppDomain.UnhandledException event.

I prefer to use try-catch statements to catch the exceptions as they occur.
This will allow you to catch exceptions on a per-mdi basis as it will catch
the exception immediately so you have the full context available to your
code.

"JWA" <ne********@armantrout.us> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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.ApartmentSta te = 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

Jul 21 '05 #2

"David Levine" <no****************@wi.rr.com> wrote in message
news:O3**************@TK2MSFTNGP09.phx.gbl...
I prefer to use try-catch statements to catch the exceptions as they occur. This will allow you to catch exceptions on a per-mdi basis as it will catch the exception immediately so you have the full context available to your
code.

That's not always possible if a control throws an exception.

-- Alan
Jul 21 '05 #3

"Alan Pretre" <no@spam> wrote in message
news:ev**************@TK2MSFTNGP10.phx.gbl...

"David Levine" <no****************@wi.rr.com> wrote in message
news:O3**************@TK2MSFTNGP09.phx.gbl...
I prefer to use try-catch statements to catch the exceptions as they occur.
This will allow you to catch exceptions on a per-mdi basis as it will

catch
the exception immediately so you have the full context available to your
code.




That's not always possible if a control throws an exception.

It depends if you are wrapping the control's execution thread in its
entirety or if it throws the exception on another thread, or in a code path
that the try-catch does not cover. Obviously a great deal depends on how the
code is structured, and it is too complicated to fully describe in a single
email. What I said earlier in that exchange partially describes the problem
and a workaround. Subscribing to the Application.ThreadException will not
catch all exceptions, only those that occur on the thread the winform itself
is on. If a control starts another thread (e.g. a background worker thread)
and it throws an exception, it will not be seen by the
Application.ThreadException handler. Conversely, wrapping a single code-path
may not catch all the exceptions either.

Jul 21 '05 #4

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

Similar topics

1
5764
by: Babu | last post by:
Hi, I am a Perl newbie and have a doubt on Perl exception handling. My understanding regarding exception handling is execute a piece of code, if any exception occurs, handle the exception and...
3
5110
by: Ryan | last post by:
I have a problem with record locking / blocking within an application. The app is quite straight forward. Written in Delphi 5 using BDE to access a SQL 7 database (Win2K server). Every so often...
6
2322
by: Daniel Wilson | last post by:
I am having exception-handling and stability problems with .NET. I will have a block of managed code inside try...catch and will still get a generic ..NET exception box that will tell me which...
0
1155
by: Piotr Szukalski | last post by:
Hi! I have a quite tricky question about .NET debugger: do I need to install the whole SDK to make SDK CLR debugger working? The situation is as follows: I have an application deployed to 130...
13
2723
by: Steve Jorgensen | last post by:
== On Error Resume next, and Err.Number == If you want to call one of your procedures from another procedure, and check for errors afterward, you mayimagine that you should write code something...
13
4432
by: Thelma Lubkin | last post by:
I use code extensively; I probably overuse it. But I've been using error trapping very sparingly, and now I've been trapped by that. A form that works for me on the system I'm using, apparently...
5
2556
by: juergen perlinger | last post by:
Hello out there. sometimes I need to have proper control of the floating point arithmetic of the C(and C++) runtime system, and using the f.p. exception handling of the C99 standard is quite...
19
2150
by: KKramsch | last post by:
One of the features from other languages that I miss most in C is trappable exceptions. More specifically, I think it's great to be able to demarcate a whole block of code where several exceptions...
3
287
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...
0
7296
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7364
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7017
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7470
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4696
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3186
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1524
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
751
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.