Thread Subject: Java Exception Object

Subject: Java Exception Object

From: rtServo

Date: 1 Dec, 2007 02:39:50

Message: 1 of 4

We have a Matlab application that uses Java to connect to some
hardware. The Java code can throw an exception which Matlab converts
to a Matlab exception which is pretty much just the text. We don't
see any way to recover the contents of the Java Exception Object which
contians useful information about what happened. Does anyone have any
suggestions?

rt

Subject: Java Exception Object

From: Ed Yu

Date: 3 Dec, 2007 23:43:05

Message: 2 of 4

Here is what you could do to tap into the java Exception:

try
   ...
catch,
   s = lasterror();
   emsg = {''; ['Java Exception has been caught:'];
s.message; ''};
   for i=1:size(s.stack,1),
      emsg = [emsg; [s.stack(i).file '::' s.stack(i).name
'() at ' num2str(s.stack(i).line)]];
   end
   if size(s.stack,1) > 0,
      emsg = [emsg; ''];
   end
   dialogPanel(fig.ubsMain.figure,'Error',emsg); % display
error in a dialog panel
end;

rtServo <noone@nowhere.com> wrote in message
<c6i1l3p6tdhg3q98mpf2jqp5i5i80vd76h@4ax.com>...
> We have a Matlab application that uses Java to connect to some
> hardware. The Java code can throw an exception which
Matlab converts
> to a Matlab exception which is pretty much just the text.
 We don't
> see any way to recover the contents of the Java Exception
Object which
> contians useful information about what happened. Does
anyone have any
> suggestions?
>
> rt

Subject: Java Exception Object

From: Ed Yu

Date: 3 Dec, 2007 23:47:57

Message: 3 of 4

Here is what you could do to tap into the java Exception:

try
   ...
catch,
   s = lasterror();
   emsg = {''; ['Java Exception has been caught:'];
s.message; ''};
   for i=1:size(s.stack,1),
      emsg = [emsg; [s.stack(i).file '::' s.stack(i).name
'() at ' num2str(s.stack(i).line)]];
   end
   if size(s.stack,1) > 0,
      emsg = [emsg; ''];
   end
   dialogPanel(fig.ubsMain.figure,'Error',emsg); % display
error in a dialog panel
end;

rtServo <noone@nowhere.com> wrote in message
<c6i1l3p6tdhg3q98mpf2jqp5i5i80vd76h@4ax.com>...
> We have a Matlab application that uses Java to connect to some
> hardware. The Java code can throw an exception which
Matlab converts
> to a Matlab exception which is pretty much just the text.
 We don't
> see any way to recover the contents of the Java Exception
Object which
> contians useful information about what happened. Does
anyone have any
> suggestions?
>
> rt

Subject: Java Exception Object

From: rtServo

Date: 5 Dec, 2007 02:29:58

Message: 4 of 4

On Mon, 3 Dec 2007 23:47:57 +0000 (UTC), "Ed Yu" <ekyu88@hotmail.com>
wrote:

>Here is what you could do to tap into the java Exception:
>
>try
> ...
>catch,
> s = lasterror();
> emsg = {''; ['Java Exception has been caught:'];
>s.message; ''};
> for i=1:size(s.stack,1),
> emsg = [emsg; [s.stack(i).file '::' s.stack(i).name
>'() at ' num2str(s.stack(i).line)]];
> end
> if size(s.stack,1) > 0,
> emsg = [emsg; ''];
> end
> dialogPanel(fig.ubsMain.figure,'Error',emsg); % display
>error in a dialog panel
>end;
>
>rtServo <noone@nowhere.com> wrote in message
><c6i1l3p6tdhg3q98mpf2jqp5i5i80vd76h@4ax.com>...
>> We have a Matlab application that uses Java to connect to some
>> hardware. The Java code can throw an exception which
>Matlab converts
>> to a Matlab exception which is pretty much just the text.
> We don't
>> see any way to recover the contents of the Java Exception
>Object which
>> contians useful information about what happened. Does
>anyone have any
>> suggestions?
>>
>> rt

Thanks Ed, but that does not get the Java exception object, but rather
it only supplies the exception message string and the call stack.
There is lots more information in the object itself.

rt

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
java exception handling Ed Yu 3 Dec, 2007 18:45:07
java Ed Yu 3 Dec, 2007 18:45:07
exception Ed Yu 3 Dec, 2007 18:45:07
java Yair Altman 1 Dec, 2007 13:18:15
rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com