Explicitly resets all the properties of the Err object after an error has been handled.
You need to clear the Err object only if you need to reference its
properties for another error within the same subroutine or before
Next statement within
the same subroutine.
On Error Resume Next i = oObjectOne.MyFunction(iVar) If Err.Number <> 0 Then MsgBox "The Error : " & Err.Description & vbCrLf _ & " was generated in " & Err.Source Err.Clear End If j = oObjectTwo.YourFunction(iVar) If Err.Number <> 0 Then MsgBox "The Error : " & Err.Description & vbCrLf _ & " was generated in " & Err.Source Err.Clear End If
Resetting the Err object explicitly using the Clear method is
necessary when you use
Next and test the value
Err.Number repeatedly. Unless you reset
the Err object, you run the very real risk of catching the previously
handled error, the details of which are still lurking in the Err
The Err object is automatically reset when an
Resume Next statement is
It is also possible to set the Err.Number property to instead of calling up the Err.Clear method. However, this doesn’t reset the remaining properties of the Err object.
When testing the value of
Err.Number, don’t forget that OLE servers often return “negative” numbers. Actually internally they’re not really negative; they’re unsigned longs, but because VBScript has ...