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


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

Error handling problem

From a@b.com
Newsgroups comp.lang.basic.visual.misc
Subject Error handling problem
Date 2012-02-07 14:55 -0800
Organization NewsGuy - Unlimited Usenet $19.95
Message-ID <tk93j79l1o14ffsp3q62mg3pj512i7eo7t@4ax.com> (permalink)

Show all headers | View raw


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
  

Back to comp.lang.basic.visual.misc | Previous | NextNext 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