Skupiny Google už nepodporují nová předplatná ani příspěvky Usenet. Historický obsah lze zobrazit stále.

Trapping java errors

0 zobrazení
Přeskočit na první nepřečtenou zprávu

William Slater

nepřečteno,
16. 10. 2008 16:44:0316.10.08
komu:
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

nepřečteno,
16. 10. 2008 23:53:0216.10.08
komu:
"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

nepřečteno,
17. 10. 2008 11:56:0017.10.08
komu:
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 nových zpráv