ClassMicrosoft.VisualBasic.Information SyntaxDim result As Boolean = IsError(expression)
DescriptionThe IsError function indicates whether an object is an instance of the System.Exception class or one of its derived classes (true) or not (False). ExampleThe 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 DifferencesIn 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 AlsoException Class |