IsError Function

   
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

   


VB.Net Language in a Nutshell
VB.NET Language in a Nutshell
ISBN: B00006L54Q
EAN: N/A
Year: 2002
Pages: 503

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net