TypeMismatchException Exception

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


Notes

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.


Example

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 block displays a message box, allowing the developer to track down the problem. Exception handling prevents the built application from quitting when the error occurs.

Dim v as Variant
Dim i as Integer
v=ProductLogo //a picture
i=v
Exception err
If err IsA TypeMismatchException then
  MsgBox "The variable i must be assigned a number!"
end if

See Also

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