com.mathwo​rks.toolbo​x.javabuil​der.MWExce​ption: Unknown exception

33 views (last 30 days)
I am compiling a Java library from Matlab code using the Matlab Library Compiler.
Using Matlab 2020a, the compiler also generates an Java example code to call the library.
Executing this example, I get the following error:
Caught "std::exception" Exception message is:
Unknown exception
... Matlab M-code Stack Trace ...
com.mathworks.toolbox.javabuilder.MWException: Unknown exception
at com.mathworks.toolbox.javabuilder.internal.MWMCR.mclFeval(Native Method)
at com.mathworks.toolbox.javabuilder.internal.MWMCR.access$600(MWMCR.java:33)
at com.mathworks.toolbox.javabuilder.internal.MWMCR$6.mclFeval(MWMCR.java:897)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at com.mathworks.toolbox.javabuilder.internal.MWMCR$2.invoke(MWMCR.java:784)
at com.sun.proxy.$Proxy0.mclFeval(Unknown Source)
at com.mathworks.toolbox.javabuilder.internal.MWMCR.invoke(MWMCR.java:447)
at callReggui.Reggui.callReggui(Reggui.java:172)
at MyCallReggui.callRegguiExample(MyCallReggui.java:22)
at MyCallReggui.main(MyCallReggui.java:51)
When I compile the library, using Matlab 2017b, I can call into the library just fine and don't get the "Unknown exception".
I'm using the Amazon Corretto JDK 11 as my Java JDK.
The Matlab code that I'm compiling into the library reads DICOM images, so it uses the Image Processing toolbox.
Debugging the call, it appears that when MWMCR.mclFeval is executed, the static fields of MWArray get initialized, which initializes MWArray.EMPTY_ARRAY. After that, the Exception appears to be thrown (still in the static initialization of MWArray), but I'cant track it down further.
I appreciate any ideas of why this Exception is thrown and how to resolve it, since I would prefere to move from 2017b to 2020a.
Greetings,
Felix
EDIT:
When I run the code directly within Matlab 2020a (no compilation to a Java library), it works fine.

Accepted Answer

Felix M
Felix M on 29 Apr 2021
Edited: Felix M on 29 Apr 2021
I finaly found the root cause for my particular case.
The MWException: Unknown exception was thrown because of the line:
rehash toolboxcache
Which was in the matlab code that I compiled to a jar.
To identify this, I created a simple java example project, from which I called the generated jar.
Inside the matlab code that gets bundled into the jar, I placed fprintf() statements.
This allowed checking, how far the code got executed, from the example project's console output.
Hope this helps anyone who enconters a simmilar issue.
Greetings,
Felix

More Answers (0)

Categories

Find more on Java Package Integration in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!