How to catch an exception in a form?

P

Paul Wu

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
 
S

stand__sure

Paul said:
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...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top