External Interfaces/API |
How MATLAB Handles Undefined Methods
If your MATLAB command invokes a nonexistent method on a Java object, MATLAB looks for a built-in function with the same name. If MATLAB finds a built-in function of that name, it attempts to invoke it. If MATLAB does not find a function with that name, it displays a message stating that it cannot find a method by that name for the class.
For example, MATLAB has a built-in method named size
, and the Java API java.awt.Frame
class also has a size
method. If you call size
on a Frame
object, the size
method defined by java.awt.Frame
is executed. However, if you call size
on an object of java.lang.String
, MATLAB does not find a size
method for this class. It executes the MATLAB size
built-in instead.
Note When you define a Java class for use in MATLAB, avoid giving any of its methods the same name as a MATLAB built-in function. |
How MATLAB Handles Java Exceptions
If invoking a Java method or constructor throws an exception, MATLAB catches the exception and transforms it into a MATLAB error. MATLAB puts the text of the Java error message into its own error message. Receiving an error from a Java method or constructor has the same appearance as receiving an error from an M-file.
Java Methods That Affect MATLAB Commands | Working with Java Arrays |