473,387 Members | 1,431 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to catch an exception in a form?

Suppose I have a form (frmMain) and a class (CheckStatus) that is
instantiated on Form_Load.
A [Start] button on the frmMain calls the CheckStatus.StartTimer method. The
timer fires every second and calls the CheckStatus.Timer_Tick method.

The code inside Timer_Tick is wrapped in a Try Catch block. Let's say
something goes wrong inside Timer_Tick and an exception is properly thrown.

Since the Timer_Tick is fired independently of the execution path on the
frmMain, how do I catch the exception in the Form?

Your input is much appreciated.

Thanks,
Paul Wu
Nov 21 '05 #1
1 1167

Paul Wu wrote:
Suppose I have a form (frmMain) and a class (CheckStatus) that is
instantiated on Form_Load.
A [Start] button on the frmMain calls the CheckStatus.StartTimer method. The timer fires every second and calls the CheckStatus.Timer_Tick method.

The code inside Timer_Tick is wrapped in a Try Catch block. Let's say something goes wrong inside Timer_Tick and an exception is properly thrown.
Since the Timer_Tick is fired independently of the execution path on the frmMain, how do I catch the exception in the Form?

Your input is much appreciated.

Thanks,
Paul Wu


For the mechanics of SEH to work properly and efficiently, you should
catch the exception at the lowest possible level -- the alternative
would be a fairly sizeable stack unwind -- this is not something that
you really want to have happen in your main loop...

what I am not understanding in your question is why it matters which
thread catches the exception... so long as your app handles it
properly, this shouldn't be an issue... now, if you need some other
process to abort on failure in response to the exception, raise an
event or marshal the call by using BegingInvoke...

Nov 21 '05 #2

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

Similar topics

10
by: Gary.Hu | last post by:
I was trying to catch the Arithmetic exception, unsuccessfully. try{ int a = 0, b = 9; b = b / a; }catch(...){ cout << "arithmetic exception was catched!" << endl; } After ran the program,...
5
by: Jacek Dziedzic | last post by:
Hi! In my main() function I have a last-resort exception construct that looks like this: int main() { try { // ... program code }
24
by: Steven T. Hatton | last post by:
If I understand correctly, I have no assurance that I can determine the type of a simple class instance thrown as an exception unless I explicitly catch it by name. (non-derived classes having no...
6
by: DraguVaso | last post by:
Hi, In my application, on some given actions while debugging in Visual Studio, I suddenly get a "System.ComponentModel.Win32Exception was unhandled" Message="Error creating window handle."...
5
by: David | last post by:
I am having a bit of a problem with catching an exception within a thread. Here is the scenario: I have a Windows Form. I create a new thread. This new thread calls a method in another DLL...
11
by: Pohihihi | last post by:
I was wondering what is the ill effect of using try catch in the code, both nested and simple big one. e.g. try { \\ whole app code goes here } catch (Exception ee) {}
23
by: VB Programmer | last post by:
Variable scope doesn't make sense to me when it comes to Try Catch Finally. Example: In order to close/dispose a db connection you have to dim the connection outside of the Try Catch Finally...
3
by: will | last post by:
Hi all. I've got an question about how to catch an exception. In Page_Load, I place a DataGrid, dg1, into edit mode. This will call the method called GenericGridEvent. GenericGridEvent will call...
5
by: Simon Tamman {Uchiha Jax} | last post by:
Now this is bugging me. I just released software for a client and they have reported an unhandled stack overflow exception. My first concern is that the entirity of the UI and any threaded...
4
by: bad_boyu | last post by:
Hello, I have the following code: try { Salarii.Editors.AngajatiNewFrm _angNewFrm = new Salarii.Editors.AngajatiNewFrm(); _angNewFrm.Connection = this.Connection; _angNewFrm.ShowInTaskbar =...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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
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...

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.