O'Reilly logo

VB.NET Language in a Nutshell, Second Edition by Steven Roman PhD, Paul Lomax, Ron Petrusha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

IsError Function

Class

Microsoft.VisualBasic.Information

Syntax

IsError(expression)
expression (required; 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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required