Clear Method

Clears all property settings of the Err object.

Syntax

object.Clear

Arguments:

Object: Required. Always the Err object.

Remarks

Use Clear to explicitly clear the Err object after an error has been handled. This is necessary, for example, when you use deferred error handling with On Error Resume Next. BSL calls the Clear method automatically whenever any of the following statements is executed:

On Error Resume Next
Exit Sub
Exit Function

The following example illustrates use of the Clear method.

Example 1:

Sub RaiseAndClearError()
    On Error Resume Next       ' Enable error handling.
    Err.Raise 6                ' Raise an overflow error.
     Output1 =  "error number here " & Err.Number     

     Err.Clear                  ' Clear the error.
    ' Check if the error is cleared.
Output2 = "error number is cleared here " & Err.Number
End Sub
'Output1: error number here 6
'Output2: error number is cleared here 0

Example 2:

Sub InnerProcedure()
    On Error Resume Next
    Err.Raise 9         
    Output1 = "Raising error here " & Err.Number
    Err.Clear           
    Output2 = "Error cleared here " & Err.Number
End Sub
Sub OuterProcedure()
    On Error Resume Next
    InnerProcedure      ' Call the inner procedure.
   'OuterProcedure Completed
End Sub
Call OuterProcedure

'Output1: Raising error here 9
'Output2: Error cleared here 0