Hi Friends,
I am actually coding in VBA and could not find a better forum that could answer my question...
I have 3 functions, one calling other and each call being handled by an error handler:
Function A:
_________
Top_A:
On Error Goto ErrHndl_A
B() ' call to function B()
ErrHndl_A:
GoTo Top_A
Function B:
_________
Top_B:
On Error Goto ErrHndl_B
C()
ErrHndl_B:
GoTo Top_B
Function C:
_________
Dim Cntr
Cntr := 0
Top_C:
On Error Goto ErrHndl_C
ErrHndl_C:
If(Cntr <> 100) Then
Cntr := Cntr + 1
GoTo Top_C
End If
MsgBox("Error in C")
The program starts with a call for function A(). I get an error in C() and I was expecting that C() would loop 100 times and finally give the MsgBox text. But, fortunately thou, the flow is a bit different:
1) A() -> B() -> C()
2) Error occurs in C() and ErrHndl_C handles it and control passes to Top_C.
3) Error occurs again in C(). Now strangely ErrHndl_B handles this error and control passes to Top_B
4) This results in another call to C().
5) Error occurs as usual in C() and ErrHndl_C handles it and control passes to Top_C.
6) Error occurs again in C(). Now ErrHndl_A handles this error and control passes to Top_A
7) Control at Top_A otherwise means re-execution of the whole program and no error occurs in C() this time and program runs to completion. The re-execution leading to completion of the program is as expected.
The program is running well by clearing the error, but I don't understand why C()'s error handler is not looping for 100 times and giving the message box text. Instead the above sequence of steps is occuring.
Can somebody explain why this is happening or am I missing something...
Thanks,
Phani
I am actually coding in VBA and could not find a better forum that could answer my question...
I have 3 functions, one calling other and each call being handled by an error handler:
Function A:
_________
Top_A:
On Error Goto ErrHndl_A
B() ' call to function B()
ErrHndl_A:
GoTo Top_A
Function B:
_________
Top_B:
On Error Goto ErrHndl_B
C()
ErrHndl_B:
GoTo Top_B
Function C:
_________
Dim Cntr
Cntr := 0
Top_C:
On Error Goto ErrHndl_C
ErrHndl_C:
If(Cntr <> 100) Then
Cntr := Cntr + 1
GoTo Top_C
End If
MsgBox("Error in C")
The program starts with a call for function A(). I get an error in C() and I was expecting that C() would loop 100 times and finally give the MsgBox text. But, fortunately thou, the flow is a bit different:
1) A() -> B() -> C()
2) Error occurs in C() and ErrHndl_C handles it and control passes to Top_C.
3) Error occurs again in C(). Now strangely ErrHndl_B handles this error and control passes to Top_B
4) This results in another call to C().
5) Error occurs as usual in C() and ErrHndl_C handles it and control passes to Top_C.
6) Error occurs again in C(). Now ErrHndl_A handles this error and control passes to Top_A
7) Control at Top_A otherwise means re-execution of the whole program and no error occurs in C() this time and program runs to completion. The re-execution leading to completion of the program is as expected.
The program is running well by clearing the error, but I don't understand why C()'s error handler is not looping for 100 times and giving the message box text. Instead the above sequence of steps is occuring.
Can somebody explain why this is happening or am I missing something...
Thanks,
Phani