This documentation is archived and is not being maintained.

ErrObject.Clear Method

Clears all property settings of the Err object.

Namespace:  Microsoft.VisualBasic
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)

public void Clear()

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 Resume statement

  • Exit Sub, Exit Function, or Exit Property

  • Any On Error statement

  • Any Try...Catch...Finally statement

    NoteNote

    The On Error Resume Next construct may be preferable to On Error GoTo when handling errors generated during access to other objects. Checking Err after 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 in Err.Number, as well as which object originally generated the error (the object specified in Err.Source).

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


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show: