Contenido principal

com.mathworks.matlab.exceptions.MatlabNotAvailableException

Java exception that indicates MATLAB Runtime is not available or cannot be launched

Since R2026a

Description

MatlabNotAvailableException is an exception that indicates that MATLAB® Runtime cannot be accessed or initialized. This exception extends java.util.concurrent.ExecutionException and serves as a critical signal that MATLAB Runtime is unavailable for computation.

This exception is thrown in several key scenarios:

  • When attempting to start a MATLAB Runtime instance via startMatlab() or startMatlabAsync() and the runtime cannot be launched.

  • When the MATLAB client has already been terminated through the terminateMatlabClient() method.

  • When the MATLAB client failed to initialize properly.

  • When attempting to close a MATLAB Runtime instance via the close() method and the runtime fails to exit properly.

Example

public class Example {
    public static void main(String[] args) {
        String ctfPath = "C:/path/to/your/ctf";
        
        try (MatlabRuntime runtime = MatlabRuntime.startMatlab(ctfPath)) {
            // Execute MATLAB function
            double[][] result = runtime.feval(1, "mymagic", 3);
            
            // Print results
            for (double[] row : result) {
                System.out.println(Arrays.toString(row));
            }
            
        } catch (MatlabNotAvailableException e) {
            // Handle case where MATLAB Runtime is not available
            System.out.println("MATLAB Runtime could not be started or terminated: " + e.getMessage());
            
        } catch (InterruptedException e) {
            System.out.println("Operation was interrupted: " + e.getMessage());
            Thread.currentThread().interrupt(); // Restore interrupted status
            
        } catch (IllegalArgumentException | IllegalStateException e) {
            // These can also be thrown by startMatlab
            System.out.println("Invalid arguments or state: " + e.getMessage());
            
        } catch (UnsupportedTypeException e) {
            // This can be thrown by feval
            System.out.println("Unsupported type in function call: " + e.getMessage());
        }
    }
}

Version History

Introduced in R2026a