
ERROR Handling craps out after 1 loop??
Quote:
> Folks,
> Could anyone shed some light on this bizzare phenomena?
> I have procedure X calling procedure A in a loop.
> Procedure A calls procedure B.
> Procedure B throws an error using Err.Raise.
> Procedure X has the error handling routine and it should grab the error. It
> does the first time, but refuses to do it any more. What am I missing
> here???
> Attached is the simple code:
> -----------------------------------------------
> Private Sub Command1_Click()
> For i = 1 To 10
> On Error GoTo this1
> f1
Who needs the function calls? Just use: MsgBox i / 0
Quote:
> GoTo skip1
> this1:
> MsgBox "this1 hit!" 'This only gets visited once! Why?
You never leave the "error handler" mode. Until you do a Resume [whatever],
an Exit Sub, or an *undocumented* On Error GoTo -1, you're still within the
error handler. Maybe if you put a Resume skip1 here:
Resume skip1
Quote:
> skip1:
> On Error GoTo 0
> Next i
> End Sub
There's a good reason most developers put the error handlers at the end of
the function or subroutine -- it's much easier to remember that you're in
"sudden death" while the error handler is running, and it's much harder to
jump back into the "real" code without first leaving "sudden death" mode.
--
Joe Foster <mailto:jlfoster%40znet.com> Sign the Check! <http://www.xenu.net/>
WARNING: I cannot be held responsible for the above They're coming to
because my cats have apparently learned to type. take me away, ha ha!