a***@b.com
2012-02-07 22:55:37 UTC
In the following code the first time an error occurs in (code 2) the
error handler goes to Err_Label2.
But on the next loop iteration if an error occurs in block (code 2)
neither of the error handlers are called.
The error is thrown back to the caller that called MyFunction.
It is as if on the second iteration the error handler
"On Error Goto 0" is in effect.
Can anyone reproduce and/or explain this behavior?
Function MyFunction()
Dim ErrNum
On Error Goto Err_Label
(code 1 - read recordset MyRs)
MyRs.MoveFirst
Do Until MyRs.EOF
On Error Goto Err_Label2
(code 2)
Err_Label2:
ErrNum = Err.Number
Err.Clear
On Error Goto Err_Label
If ErrNum <> 0 Then
(do something)
Else
(do something else)
End If
MyRs.MoveNext
Loop
Exit_Label:
(cleanup code)
Exit Function
Err_Label:
(code)
Resume Exit_Label
End Function
error handler goes to Err_Label2.
But on the next loop iteration if an error occurs in block (code 2)
neither of the error handlers are called.
The error is thrown back to the caller that called MyFunction.
It is as if on the second iteration the error handler
"On Error Goto 0" is in effect.
Can anyone reproduce and/or explain this behavior?
Function MyFunction()
Dim ErrNum
On Error Goto Err_Label
(code 1 - read recordset MyRs)
MyRs.MoveFirst
Do Until MyRs.EOF
On Error Goto Err_Label2
(code 2)
Err_Label2:
ErrNum = Err.Number
Err.Clear
On Error Goto Err_Label
If ErrNum <> 0 Then
(do something)
Else
(do something else)
End If
MyRs.MoveNext
Loop
Exit_Label:
(cleanup code)
Exit Function
Err_Label:
(code)
Resume Exit_Label
End Function