Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.basic.visual.misc > #748

Re: Error handling problem

From Deanna Earley <dee.earley@icode.co.uk>
Newsgroups comp.lang.basic.visual.misc
Subject Re: Error handling problem
Date 2012-02-08 09:18 +0000
Organization Aioe.org NNTP Server
Message-ID <jgtekj$a0j$1@speranza.aioe.org> (permalink)
References <tk93j79l1o14ffsp3q62mg3pj512i7eo7t@4ax.com>

Show all headers | View raw


On 07/02/2012 22:55, a@b.com wrote:
>
> 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.

Almost, Once you it hits an "On Error Goto XX" handler, then it is IN 
that handler and you MUST "Resume XXX" to continue.
In your case, it jumps into the error handler on the first iteration.
On the 2nd iteration, it's already in that handler (regardless of where 
in the procedure it is) and it jumps up to the error handler in the 
calling code.

> 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
       If ErrNum <>0 then
>        Err.Clear
>
>        On Error Goto Err_Label
>
>        If ErrNum<>  0 Then
>          (do something)
>        Else
>          (do something else)
>        End If
          Resume Err_LabelCont
       End If
Err_LabelCont:
>
>        MyRs.MoveNext
>
>     Loop
>
> Exit_Label:
>     (cleanup code)
>
>     Exit Function
>
> Err_Label:
>     (code)
>     Resume Exit_Label
>
> End Function

An alternative to the On Error, Resume model is to use On Error Resume 
Next and explicitly check the value of Err.Number afterwards.
If you have a block of code, you will need to check after every call to 
stop it trying to carry on until it gets to the error check.

-- 
Deanna Earley (dee.earley@icode.co.uk)
i-Catcher Development Team
http://www.icode.co.uk/icatcher/

iCode Systems

(Replies direct to my email address will be ignored.
Please reply to the group.)

Back to comp.lang.basic.visual.misc | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Error handling problem a@b.com - 2012-02-07 14:55 -0800
  Re: Error handling problem Deanna Earley <dee.earley@icode.co.uk> - 2012-02-08 09:18 +0000
    Re: Error handling problem a@b.com - 2012-02-08 11:22 -0800

csiph-web