1

Im in the place that I have to develop an interface in Java to work with from matlab. However I currently don't have access to matlab. For using the interface and handling errors I'd like to use exceptions, as they would be easy to use.

Is it possible to catch a java exception in matlab?

2 Answers 2

1

Yes, it's possible to catch a java exception using the MATLAB try/catch block like this:

j = java.lang.String('foo');
try
    j.substring(-2);
catch E
    fprintf('Caught this: %s\n', getReport(E));
end

which results in this:

Caught this: Java exception occurred: 
java.lang.StringIndexOutOfBoundsException: String index out of range: -2
    at java.lang.String.substring(Unknown Source)
Sign up to request clarification or add additional context in comments.

Comments

1

Of course, here's how (see "Examples").

Because StackOverflow requires minimum 30 chars in the message body, this statement serves as filler.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.