清除 Err 物件的所有特性設定值。
語法
object.Clear
引數:
Object:必要。一律使用 Err 物件。
備註
使用 Clear 可在處理錯誤後明確清除 Err 物件。例如,當您對 On Error Resume Next 使用遞延錯誤處理時,此為必要項目。每當執行下列任一陳述式時,BSL 都會自動呼叫 Clear 方法:
On Error Resume Next Exit Sub Exit Function
下列範例說明 Clear 方法的用法。
範例 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
範例 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