How to catch an exception in a form?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paul Wu

    #1

    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.Sta rtTimer method. The
    timer fires every second and calls the CheckStatus.Tim er_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


  • stand__sure

    #2
    Re: How to catch an exception in a form?


    Paul Wu wrote:[color=blue]
    > 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.Sta rtTimer[/color]
    method. The[color=blue]
    > timer fires every second and calls the CheckStatus.Tim er_Tick method.
    >
    > The code inside Timer_Tick is wrapped in a Try Catch block. Let's say[/color]
    [color=blue]
    > something goes wrong inside Timer_Tick and an exception is properly[/color]
    thrown.[color=blue]
    >
    > Since the Timer_Tick is fired independently of the execution path on[/color]
    the[color=blue]
    > frmMain, how do I catch the exception in the Form?
    >
    > Your input is much appreciated.
    >
    > Thanks,
    > Paul Wu[/color]

    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...

    Comment

    Working...