473,659 Members | 2,683 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.Threadin g.Thread.Curren tThread.Apartme ntState = System.Threadin g.ApartmentStat e.STA
Dim eh As New MyExceptionHand ler()
AddHandler Application.Thr eadException, AddressOf eh.OnThreadExce ption
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 1418
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.Thr eadException 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.Unhan dledException 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********@arm antrout.us> wrote in message
news:%2******** ********@TK2MSF TNGP10.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.Threadin g.Thread.Curren tThread.Apartme ntState = System.Threadin g.ApartmentStat e.STA Dim eh As New MyExceptionHand ler()
AddHandler Application.Thr eadException, AddressOf eh.OnThreadExce ption 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******** ******@TK2MSFTN GP09.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******** ******@TK2MSFTN GP10.phx.gbl...

"David Levine" <no************ ****@wi.rr.com> wrote in message
news:O3******** ******@TK2MSFTN GP09.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.Thr eadException 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.Thr eadException 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
5783
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 proceed as if the error never occurred at all. So code would look like Eval { # do something }; if ($@)
3
5119
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 the users (when they bother to tell me) find that the application locks up and they are unable to work. No errors are produced (error trapping in the app is good). They 'shout round' to each other and get someone to exit the data entry screen....
6
2335
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 assemblies are loaded before shutting down. In one case, some of my DB-accessing code didn't handle a NULL value properly. But try...catch wouldn't catch the exception and keep going. I'd just get the error message and then it would shut the...
0
1171
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 computers and everywhere it works just fine. Everywhere but two machines... _important_ machines... I see there is no other way to sit by the computers and investigate the issue. To do so I need a debugger - it's enought if it can tell me where an...
13
2742
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 like this... On Error Resuse Next MyFoo 123 lngErrNum = Err.Number On Error Goto 0
13
4470
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 runs into problems on the system where it will actually be used, and since I used so little error-trapping it dies very ungracefully. I will of course try to fix whatever is causing the error and add error-trapping to the functions where the...
5
2563
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 handy for that purpose. The only problem when dealing with f.p. exception signals is that there is (afaik) no specification *when* the f.p. exception is raised, with one notable exception: 'feraiseexcept(int)' raises the exceptions passed in the...
19
2175
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 can happen at various points, so that any one of these exceptions can be trapped and handled by the exception-handling code collected in one place after the block. This also means that the exception generating code can be much cleaner, since...
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 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()
0
8427
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8332
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8746
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8525
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7356
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4175
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1975
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.