From Xojo Documentation

Class (inherits from RuntimeException)

Occurs when you try to assign a value to an object that is an incorrect data type.

ErrorNumber Message Reason fa-lock-32.png
Stack StackFrames


A TypeMismatchException error occurs when you try to assign a value of an incorrect data type to an object. This error can occur only if the compiler cannot determine the type of the value at compile time - for example, when using variants. Ordinarily, the compiler catches incorrect typing when you try to compile the application.

Sample Code

The following code assigns a picture that has been added to the Project Editor to the variant, v, and then tries to assign v to an Integer. The Exception statement displays a message box, allowing the developer to track down the problem. Exception handling prevents the built application from quitting when the error occurs.

Var v As Variant
Var i As Integer
v = ProductLogo // a picture
i = v
Exception err
If err IsA TypeMismatchException Then
MessageBox("The variable i must be assigned a number!")
End If

See Also

RuntimeException class; Function, Raise, Sub statements; Nil datatype; Exception, Try statements.