javachk

Error message based on Java feature support

Syntax

  • MSG = javachk(feature)
  • javachk(feature,component)

Description

MSG = javachk(feature) returns a generic error message if the specified Java® feature is not available in the current MATLAB® session.

javachk(feature,component) also names the specified component in the error message.

Examples

expand all

Generate Error

if isempty(javachk('jvm'))
   scalar = java.lang.Double(5);
end
% Check that JVM is available & JavaFigures are supported
error(javachk('jvm'))
error(javachk('awt'))

Generate Error in User-Defined Script

If you write a script, myFile, that displays a Java Frame and want it to error gracefully if a frame cannot be displayed, do the following:

error(javachk('awt','myFile'));
myFrame = java.awt.Frame;
myFrame.setVisible(1);

If the script cannot display a frame, it displays this error:

myFile is not supported on this platform.

Input Arguments

expand all

feature — Java feature'awt' | 'desktop' | 'jvm' | 'swing'

Java feature, specified as one of these values:

'awt'

Java GUI components in the Abstract Window Toolkit (AWT) components are available.

'desktop'

MATLAB interactive desktop is running.

'jvm'

Java Virtual Machine software (JVM™) is running.

'swing'

Swing components (Java lightweight GUI components in the Java Foundation Classes) are available.

component — Identifierstring

Identifier, specified as a string, to display in the error message.

Data Types: char

Output Arguments

expand all

MSG — Error messagestructure

Error message, returned as a structure with these fields:

If it is available, javachk returns an error structure with empty message and identifier fields.

message — Messagestring | empty

Message, specified as a string.

identifier — Identifierstring | empty

Identifier, specified as a string.

See Also

|

Was this topic helpful?