|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
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? 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 Show quoteHide quote "Nobody" <trin***@nobody.com> wrote in message news:%23b6MtsOnJHA.3504@TK2MSFTNGP06.phx.gbl... > http://support.microsoft.com/kb/191474 > > http://www.aivosto.com/vbtips/errorhandling.html > > http://www.freevbcode.com/ShowCode.asp?ID=2165 > > Claus Centrino wrote:
> An On Error Goto in an event handler can catch all errors in all Correct.> underlaying subs (if they don't have their on error handler). It's a /safe/ way of coding, preventing nasty errors "leaking" out of your code and crashing the entire program. > This way still each event handler in an app must have its own On Error Correct.> 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 No.> so that I don't have an individual On Error Goto in each event handler sub? 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.
Show quote
Hide quote
"Phill W." <p-.-a-.-w-a-r-d-@-o-p-e-n-.-a-c-.-u-k> wrote I would have thought he was looking for something more like:> 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. 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
Please help to translate this short Delphi code
close excel from VB6 How difficult is to add my menu to Windows Explorer? Use Proc with Static Variables Multiple Times Error Message Help Write in C OT MS Community Visibility Unbelieveable code, it produces one result in VB6 run and another if compiled in a exe file ???? Wha Vista behaves differently to WordBasic command even though same version of Word! How to add new rows to Listview |
|||||||||||||||||||||||