ErrObject.Clear Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Clears all property settings of the Err object.
public:
void Clear();
public void Clear();
member this.Clear : unit -> unit
Public Sub Clear ()
Examples
This example uses the Err object's Clear method to reset the numeric properties of the Err object to zero and its string properties to zero-length strings. Without the call to Clear, the second call to MsgBox would display the same error message.
Sub ClearErr()
' Produce overflow error
On Error Resume Next
Dim zero As Integer = 0
Dim result As Integer = 8 / zero
MsgBox(Err.Description)
Err.Clear()
MsgBox(Err.Description)
End Sub
Remarks
Use Clear to explicitly clear the Err object after an error has been handled, such as when you use deferred error handling with On Error Resume Next. The Clear method is called automatically whenever any of the following statements executes:
Any type of
ResumestatementExit Sub,Exit Function, orExit PropertyAny
On ErrorstatementAny
Try...Catch...FinallystatementNote
The
On Error Resume Nextconstruct may be preferable toOn Error GoTowhen handling errors generated during access to other objects. CheckingErrafter each interaction with an object removes ambiguity about which object was accessed by the code: You can be sure which object placed the error code inErr.Number, as well as which object originally generated the error (the object specified inErr.Source).