Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Trapping java errors

0 views
Skip to first unread message

William Slater

unread,
Oct 16, 2008, 4:44:03 PM10/16/08
to
I've got an interactive figure made that plot's an aircraft's flight path and position. There's a slider that lets the user pick the point in time desired to see the plane's position. The position is drawn by the patch command. If the user zooms in on a portion of the graph, there is the possibility that the patch will be drawn outside of the axes' limits, which results in a java.lang.OutOfMemoryError message. Is it possible to trap such errors, say with a try/catch statement?

tia
Will

Bob Kagy

unread,
Oct 16, 2008, 11:53:02 PM10/16/08
to
"William Slater" <William....@LMCO.com> wrote in message <gd892j$mdf$1...@fred.mathworks.com>...
> ... there is the possibility ... results

> in a java.lang.OutOfMemoryError message.
> Is it possible to trap such errors, say
> with a try/catch statement?

This code appears to catch an exception from Java. However, I'm not sure about catching a java.lang.OutOfMemoryError message. I'm a little fuzzy on whether one can catch children of java.lang.Error in Java, let alone Matlab.

From the JavaDoc for java.lang.Error:
An Error is a subclass of Throwable that indicates serious problems that a reasonable application should not try to catch.

% catch_java_error.m
% A quick test to show Matlab catching a Java error.

% Create a java.lang.String, then catch the error when we pass an invalid
% argument to its substring method
js = java.lang.String('a string')
js.substring(4)
try
js.substring(10)
catch ME
disp('Caught the Java exception');
disp(ME);
disp(ME.message);
end

Output:
js =

a string


ans =

ring

Caught the Java exception

MException object with properties:

identifier: 'MATLAB:Java:GenericException'
message: [1x195 char]
stack: [1x1 struct]
cause: {}

Java exception occurred:
java.lang.StringIndexOutOfBoundsException: String index out of range: -2

at java.lang.String.substring(Unknown Source)

at java.lang.String.substring(Unknown Source)

Michael Katz

unread,
Oct 17, 2008, 11:56:00 AM10/17/08
to
Will,

You won't be able to trap the error unless it's being generated from your
own Java code. However you can increase the amount of Java memory available
to MATLAB using the instructions here:

http://www.mathworks.com/support/solutions/data/1-4HCPJ8.html?product=SB&solution=1-4HCPJ8

"William Slater" <William....@LMCO.com> wrote in message

news:gd892j$mdf$1...@fred.mathworks.com...

0 new messages