IsError Function


IsError Function

Class

Microsoft.VisualBasic.Information

Syntax

     Dim result As Boolean = IsError(expression) 


expression (required; Object)

An object variable that may be a System.Exception object

Description

The IsError function indicates whether an object is an instance of the System.Exception class or one of its derived classes (true) or not (False).

Example

The following example shows how a single object may or may not be an Exception object. However, the method of indicating the error is nonstandard and is only used here as a demonstration.

     Public Sub TestForError(  )        Dim testValue As Object = "You can't increment a string!"        Dim testResult As Object        ' ----- Perform the test.        testResult = IncrementTest(testValue)        If (IsError(testResult) = True) Then           MsgBox(testResult.Message)        Else           MsgBox(testResult)        End If     End Sub     Public Function IncrementTest(ByVal testValue As Object) As Object        ' ----- Increment the value, but only if it is possible.        If (IsNumeric(testValue) = True) Then           Return testValue + 1        Else           Return New System.InvalidOperationException        End If     End Function 

Version Differences

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

See Also

Exception Class




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

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