Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Java Exception Object

Subject: Java Exception Object

From: rtServo

Date: 1 Dec, 2007 02:39:50

Message: 1 of 6

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 6

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 6

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 6

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

Subject: Java Exception Object

From: John VanLaanen

Date: 17 Mar, 2010 20:23:20

Message: 5 of 6

This is an old post, but I haven't seen if the question ever got answered and I've run into the same issue - is there any way to get access to Java's exception object when a Java exception happens in Matlab?

Thanks!

rtServo <noone@nowhere.com> wrote in message <953cl3lfn36st9elhp9c4d39j8neck5ne7@4ax.com>...
> 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

Subject: Java Exception Object

From: Yair Altman

Date: 17 Mar, 2010 21:37:21

Message: 6 of 6

"John VanLaanen" <john.vanlaanen@wdc.com> wrote ...
> is there any way to get access to Java's exception object when a Java exception happens in Matlab?


IFF the exception occurred on the main Matlab processing thread, you can trap it using the standard try-catch Matlab mechanism and examine (& possibly string-parse) the error object.

However, if the exception happened on another, asynchronous thread (e.g., the GUI EDT), you're out of luck...

More on EDT in Matlab: http://undocumentedmatlab.com/blog/matlab-and-the-event-dispatch-thread-edt/

Yair Altman
http://UndocumentedMatlab.com

Tags for this Thread

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.

Contact us