global On Error Goto ? 
Author Message
 global On Error Goto ?

An On Error Goto in an event handler can catch all errors in
all underlaying subs (if they don't have their on error
handler).
This way still each event handler in an app must have its
own On Error statement because the error label must reside
within the same sub.

Can I setup something like a global On Error Goto for all
subs in my exe so that I don't have an individual On Error
Goto in each event handler sub?



Sun, 21 Aug 2011 21:27:39 GMT  
 global On Error Goto ?
http://support.microsoft.com/kb/191474

http://www.aivosto.com/vbtips/errorhandling.html

http://www.freevbcode.com/ShowCode.asp?ID=2165



Mon, 22 Aug 2011 01:03:41 GMT  
 global On Error Goto ?
That kb article is very misleading. It suggests that every procedure needs
its own handler, but that they can share code by calling on the same global
procedure

In fact, the error handling is not per-procedure - it's stack-based. Hence,
any handler set by a procedure will automatically apply to all other
procedures called from that procedure. A procedure exception is
automatically handled by the last exception handler declared by one of its
callers (or itself of course)

In a server-side component, for instance, a handler in Main() will apply
everywhere since everything starts at Main(). Obviously, any procedure can
establish a more-specific handler for itself and anything it calls, if it
wants

The exception to this (so to speak) is event handlers. In VB, they're deemed
to run on a different stack, or at least a different area of the main stack.
As such, they don't inherit the handlers already established on the stack
when the event is fired. Hence, every VB event handler effectively needs its
own exception handler, although those exception handlers still apply to all
things called from the event handler

The only way I know to intercept them at a central point would be by using
the API SetUnhandledExceptionFilter

    Tony Proctor


Quote:
> http://support.microsoft.com/kb/191474

> http://www.aivosto.com/vbtips/errorhandling.html

> http://www.freevbcode.com/ShowCode.asp?ID=2165



Mon, 22 Aug 2011 21:18:06 GMT  
 global On Error Goto ?

Quote:

> An On Error Goto in an event handler can catch all errors in all
> underlaying subs (if they don't have their on error handler).

Correct.

It's a /safe/ way of coding, preventing {*filter*} errors "leaking" out of
your code and crashing the entire program.

Quote:
> This way still each event handler in an app must have its own On Error
> statement because the error label must reside within the same sub.

Correct.

Quote:
> Can I setup something like a global On Error Goto for all subs in my exe
> so that I don't have an individual On Error Goto in each event handler sub?

No.

The code you write might say ...

    On Error Goto Label

... but that gets compiled into P-Code or machine code logic that, when
an error happens, branches to an /single/ memory address - the one
"pointed to" by Label, wherever that might be in the context of /each/,
individual method.

I think what you're hinting at is something like

    Option DesignatedErrorHandlingLabelName = EH

    Sub1()
       ...
       Exit Sub
    EH:
       ...
    End Sub

    Sub2()
       ...
       Exit Sub
    EH:
       ...
    End Sub

Sorry; can't be done.

Regards,
    Phill  W.



Tue, 23 Aug 2011 20:23:51 GMT  
 global On Error Goto ?


Quote:
> I think what you're hinting at is something like

>     Option DesignatedErrorHandlingLabelName = EH

>     Sub1()
>        ...
>        Exit Sub
>     EH:
>        ...
>     End Sub

>     Sub2()
>        ...
>        Exit Sub
>     EH:
>        ...
>     End Sub

> Sorry; can't be done.

I would have thought he was looking for something more like:

Public Sub Main()
ReLoad:

    On Error Goto AppErr
    frmMain.Show

AppErr:

  If Err.Number Then
      Dim msg As String
      Dim btn As Long
      btn = vbYesNo Or vbCritical
      msg = "The application has encountered a critical error "
      msg = msg & "and cannot proceed with a requested operation." & vbCrLf
      msg = msg & vbCrLf & "Do you want to exit the application?"

      Select Case MsgBox(msg, btn, "Application Error!")
      Case vbNo
        Resume ReLoad
      End Select

  End If
End Sub

Assuming of course that trapping errors ahead of calling a form
would capture all unhandled exceptions from the form.

But, as others have said, it is not possible....

LFS



Tue, 23 Aug 2011 21:48:28 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Global On Error GoTo?

2. How 2 set a GLOBAL on ERROR goto ?

3. On error Goto causes error in compilation

4. Error with On Error GoTo statement

5. Error with On error Goto... Vb4 32bits

6. Error with On Error GoTo statement

7. Error when using on error goto

8. On error goto not being called when getting an error

9. On Error GoTo isn't working

10. on error goto ... statement

11. what does On error goto -1 ?

12. on error goto .... doesn't work correctly

 

 
Powered by phpBB® Forum Software