Share via


IsError 函式

更新:2007 年 11 月

傳回的 Boolean 值將說明運算式是否為例外狀況 (Exception) 類型。

Public Function IsError(ByVal Expression As Object) As Boolean

參數

  • Expression
    必要項。Object 運算式。

備註

若運算式代表 Object 變數,且該變數衍生自 System 命名空間的 Exception 類別,則 IsError 會傳回 True。

使用 Try...Catch...Finally 陳述式 (Statement),就可以攔截衍生自 System.Exception 的例外狀況。

範例

下列範例會使用 IsError 函式,來檢查運算式是否代表系統例外狀況。

Sub demonstrateIsError(ByVal firstArg As Integer)
    Dim returnVal As New Object
    Dim badArg As String = "Bad argument value"
    Dim errorCheck As Boolean
    If firstArg > 10000 Then
        returnVal = New System.ArgumentOutOfRangeException(badArg)
    End If
    errorCheck = IsError(returnVal)
End Sub

需求

命名空間Microsoft.VisualBasic

**模組︰**Information

組件 (Assembly):Visual Basic Runtime Library (在 Microsoft.VisualBasic.dll 中)

請參閱

參考

IsArray 函式 (Visual Basic)

IsDate 函式 (Visual Basic)

IsDBNull 函式

IsNothing 函式

IsNumeric 函式 (Visual Basic)

IsReference 函式

Object 資料型別

TypeName 函式 (Visual Basic)