473,499 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Windows Application error handling question

I have a usb device that controls a power supply. That usb device must
perform a procedure, named Zero_outputs(), in the event of any error.
Clearly, within my main form (the only form in this application) I can have
each method envelope a Try-Catch statement that calls Zero_outputs() in the
catch clause.

However, I fear that certain application errors might occur outside of the
context of any given method in my main form. Is there a way to execute
Zero_outputs() whenever any error, of any kind, occurs in my application?
Oct 15 '08 #1
3 1586
On 15 Oct, 21:03, Mark_B <Ma...@discussions.microsoft.comwrote:
I have a usb device that controls a power supply. That usb device must
perform a procedure, named Zero_outputs(), in the event of any error.
Clearly, within my main form (the only form in this application) I can have
each method envelope a Try-Catch statement that calls Zero_outputs() in the
catch clause.

However, I fear that certain application errors might occur outside of the
context of any given method in my main form. Is there a way to execute
Zero_outputs() whenever any error, of any kind, occurs in my application?
Use Application.ThreadException to catch exceptions in all forms
threads.
Please read carefully: http://msdn.microsoft.com/en-us/libr...exception.aspx

NOTE (from the above link):
To use this event, you must attach a handler before you call
Application..::.Run.

If an exception occurs in the main application thread and no catch
block in the call stack handles it, the default exception handler
catches it and terminates the application. If an exception occurs in a
thread other than the main application thread, the thread exits, but
the application continues to run.

AND, ALSO IMPORTANT:
Because this is a static event, you must detach your event handlers
when your application is disposed, or memory leaks will result.

Hope it helps.
Oct 15 '08 #2
However, I fear that certain application errors might occur outside of the
context of any given method in my main form. Is there a way to execute
Zero_outputs() whenever any error, of any kind, occurs in my application?
Such as what?

Oct 16 '08 #3
That's a really good question actually. I can think of two right off hand:
out of memory and stack overflow. But I do not know about others. I sense
there may be several.

The target is "intrinsic safety". I am looking for an approach which will
trap all errors, even those I do not know about as well as any I cannot
anticipate or predict.

I read nano2k's helpful article. It certainly does a nice job of terminating
the program but - and this is the clincher - prior to aborting the program a
specific method (Zero_outputs) must execute to bring pins low on a device...
shutting down a power supply. Right now I have a try statement in program.cs
that looks like this:

try
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(fals e);
Application.Run(new Form1());
}
catch
{
in here is a replica of Zero_outputs();
}

This approach seems to work pretty well in the case where an unhandled
exception occurs in a method in the application's main form (again, the only
form for this application). I could write test code that that generates stack
overflow and even out of memory errors. But, your question will still haunt
me. “Such as what”? I will wonder, is there an error type I haven't
anticipated?
Oct 16 '08 #4

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

Similar topics

0
2398
by: richardshen | last post by:
My DB2 V8 SP5 WSE crash on Windows 2003 with the following msg in db2diag.log. Any idea? Looks like I need set stackreserver, what is the suggested value for that? 2004-03-05-12.20.46.299000 ...
6
17548
by: Jon Hyland | last post by:
Ok, I'm a little rusty on this, it should be a simple problem but I can't figure it out. How can I handle form events in my main code page?? I'm creating a Windows App in C#. Rather than make...
2
9515
by: Steph | last post by:
I am working on a Windows Forms App. I have attached a standard UnhandledExceptionEventHandler to the current domain to catch unexpected errors. In my application, when I trigger an unhandled...
1
1920
by: sidd | last post by:
Hi all, how do i exit out(unload) of a windows service in case of an error. so i have a code block as follows try { } catch(exception ex) { //log to event log
2
1167
by: Phillip | last post by:
In order to maintain consistency thru a project. Our development team is getting ready to start a new project in converting all the foxpro apps to VB/SQL Server. We don't have the luxury of...
3
7468
by: Chris Paul | last post by:
I'm having trouble with PHP & PostgreSQL/OpenLDAP/Apache on Windows. I've set this up countless times on BSD (piece of cake) but I'm trying to do this on Windows now so that my developer can work...
4
3396
by: Markus Stoeger | last post by:
Hi, I have a problem with Application.Run() when Windows is shutting down. Please have a look at the copy&paste example program below. The application has no forms. It has only got a notify...
4
2162
by: David Lozzi | last post by:
Howdy, I found a nice little book called ASP.NET 2.0 Cookbook by Michael A Kittel and Geoffrey LeBlond. Anyway, they have some instructions on how to setup application level error handling. Most...
7
2582
by: Daniel | last post by:
Hello! I am having a problem with a windows application that abnormally terminates itself. The application is a multi threaded .NET 1.1 application, and can briefly be described as follows: ...
0
7174
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
7220
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
6894
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
7388
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
4919
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
4600
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
1427
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
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
297
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.