Name

IsError Function

Class

Microsoft.VisualBasic.Information

Syntax

IsError(expression)
expression

Use: Required

Data Type: Object

An object variable that may be an Exception object

Return Value

Boolean (True if expression is an Exception object, False otherwise)

Description

Indicates whether an object is an instance of the Exception class or one of its derived classes

Example

Module modMain

Public Sub Main

Dim oUnk As Object = "This is an object of subtype String."
'Dim oUnk As Object = 10
Dim oResult As Object = Increment(oUnk)
If Not IsError(oResult) Then
   Console.WriteLine(oResult)
Else
   Console.WriteLine(oResult.Message)
End If

End Sub

Public Function Increment(o As Object) As Object
   If IsNumeric(o) Then
      o += 1
      Return o
   Else
      Dim e As New System.InvalidOperationException
      Return e 
   End If
End Function

End Module

VB .NET/VB 6 Differences

In VB 6, the IsError function takes a variant argument and determines if its subtype is vbError. Most commonly, it is used with the CVErr function to determine if the value returned from a function is an error. In VB .NET, the IsError function is used to test whether an object is an instance of the Exception class or its derived classes.

See Also

Exception Class

Get VB .NET Language in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.