Why would a error handler not catch an error?

For some reason, the error handler below does NOT catch the error. This bit of code sometimes gets a error 91. I have this same type of error handler (minus the elseif err.number = 424) elsewhere in my code and it works fine. The error label is not mispelled.  I've verified the code does not even reach the ErrCoke4: label.



On Error GoTo ErrCoke4
Do Until InStr(1, IE.Document.body.innertext, "Update Records") <> 0
    txtImageCode.Text = "Looping until 'Update Records' <> 0"
    DoEvents
    If KoKoMo& < Timer Then
        Exit Do 'If the loop runs for 30 seconds, then exit the loop.
    End If
Loop





ErrCoke4:
If Err.Number = 91 Then
    txtImageCode.Text = "Err 91 - Verifying 'Update Records' page failed"
    Sleep 1
    GoTo Coke4
ElseIf Err.Number = 424 Then
    txtImageCode.Text = "Err 424 - Verifying 'Update Records' page failed"
    Sleep 1
    GoTo Coke4
Else
    Err.Raise (Err.Number & ", " & Err.Description)
End If
JohnDoeSrAsked:
Who is Participating?
 
GrahamSkanRetiredCommented:
Also, you should

Resume Coke4

otherwise you are still logically in error handling mode.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
You have this in there:

    GoTo Coke4

Where is the Coke4 label?

Can you post the entire sub/function that contains this?

There must be more there...for example, how are you preventing the code from dropping down into the error handler code when the loop is dropped out of?

etc...
0
 
junglerover77Commented:
What Idle_Mind said is absolute right.

If your Coke4 label is in somewhere prior to the code, errors will not be caught again when it was raised the second time.
0
 
tushar_compCommented:
hi,

 if this is function or sub then error handling shuld be like below

 Public Function Test()
 
  On Error GoTo ErrCoke4
  Do Until InStr(1, IE.Document.body.innertext, "Update Records") <> 0
    txtImageCode.Text = "Looping until 'Update Records' <> 0"
    DoEvents
    If KoKoMo& < Timer Then
        Exit Do 'If the loop runs for 30 seconds, then exit the loop.
    End If
  Loop
  Exit Function
 
  ErrCoke4:
            If Err.Number = 91 Then
            txtImageCode.Text = "Err 91 - Verifying 'Update Records' page failed"
            Sleep 1
            GoTo Coke4
            ElseIf Err.Number = 424 Then
            txtImageCode.Text = "Err 424 - Verifying 'Update Records' page failed"
            Sleep 1
            GoTo Coke4
            Else
            Err.Raise (Err.Number & ", " & Err.Description)
            End If

End Function

but i have one doubt
 that why r using GoTo  Coke4
 THIS means ur moving control somewhere after trapping error
 elaborate on this

 try to use err.discription what is the error in error handler that makes it more relevent
 
 if i m wromg correct me
 if all these is useful

 Let me know
 
 Tushar

 

 
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.