Contenido principal

com.mathworks.matlab.exceptions.UnsupportedTypeException

Java exception that indicates an unsupported data type in Java to MATLAB data conversion

Since R2026a

Description

UnsupportedTypeException is an exception that indicates a type conversion failure between Java® and MATLAB® data types. This exception is thrown when MATLAB Runtime encounters input or output data types that cannot be properly converted between the Java and MATLAB environments.

The exception occurs in several key scenarios:

  • When passing Java objects to MATLAB functions via feval() or fevalAsync() methods and the objects are of types that cannot be converted to MATLAB data types.

  • When retrieving results from MATLAB functions and the MATLAB output cannot be converted to the expected Java type.

Example

public class Example {
    public static void main(String[] args) {
        String ctfPath = "C:/path/to/your/ctf";
        
        try (MatlabRuntime runtime = MatlabRuntime.startMatlab(ctfPath)) {
            // Create an object of unsupported type (Thread is not convertible to MATLAB)
            Thread currentThread = Thread.currentThread();
            
            // Attempt to pass unsupported type to MATLAB function
            runtime.feval(0, "disp", currentThread);
            
        } catch (UnsupportedTypeException e) {
            // Handle unsupported type conversion
            System.out.println("Data type conversion error: " + e.getMessage());
            
        } catch (MatlabNotAvailableException | InterruptedException | 
                 IllegalArgumentException | IllegalStateException e) {
            System.out.println("Runtime error: " + e.getMessage());
        }
    }
}

Version History

Introduced in R2026a