From: John VanLaanen on
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(a)nowhere.com> wrote in message <953cl3lfn36st9elhp9c4d39j8neck5ne7(a)4ax.com>...
> On Mon, 3 Dec 2007 23:47:57 +0000 (UTC), "Ed Yu" <ekyu88(a)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(a)nowhere.com> wrote in message
> ><c6i1l3p6tdhg3q98mpf2jqp5i5i80vd76h(a)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
From: Yair Altman on
"John VanLaanen" <john.vanlaanen(a)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