User`s guide
Handling Errors
Handling Errors
Errors that occur during execution of an M-function or during data conversion
are s ignaled by a standard Java exception. This includes MATLAB run-time
errors as well as errors in your M-code.
In ge neral, there are two types of exceptions in Java: checked exceptions
and unchecked exceptions.
Handling Checked Exceptions
Checked exceptions must be de clared as thrown b y a m ethod using the Java
language
throws claus e. Java Builder components support one checked
exception:
com.mathworks.toolbox.javabuilder.MWException.This
exception class inherits from
java.lang.Exception and is thrown by every
MATLAB Compiler generated Java m ethod to signal that an error has
occurred during the call. All normal MATLAB run-time errors, as well as
user-created errors (e.g., a calling e rror in your M-code) are manifested as
MWExceptions.
The Java interface to each M-function declares itself as throwing an
MWException using the throws clause. For example, the myprimes M-function
shown previously has the following interface:
/* mlx interface List version */
public void myprimes(List lhs, List rhs) throws MWException
{
(implementation omitted)
}
/* mlx interface Array version */
public void myprimes(Object[] lhs, Object[] rhs) throws MWException
{
(implementation omitted)
}
/* Standard interface no inputs*/
public Object[] myprimes(int nargout) throws MWException
{
(implementation omitted)
}
/* Standard interface one input*/
3-19