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
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 in situations where you are using
Next and are testing the value of 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 object’s properties.
The Err object is automatically reset when either a
Error statement is executed.
You can achieve the same results by setting the Err.Number property to 0; however, your code will be more readable if you use the Clear method.
VB also supports structured error-handling through the
Internally, in VB.NET ...