Effacer les filtres
Effacer les filtres

Matlab error beep/ding with Java integration - how to actually see the error message

1 vue (au cours des 30 derniers jours)
Nikita Visnevski
Nikita Visnevski le 18 Août 2021
Modifié(e) : surya venu le 15 Avr 2024
Folks, I do a lot of calling Java from Matlab and Matlab from Java in my software all the time. I have not quite figured out what happens with the console output in all of these cases. Sometimes it shows in Matlab window, other times it does not. A good example is if I run a Java GUI from Matlab which then handles say an action event by calling Matlab back, which will call another Java function. Text output from that last function will be printed in Matlab window, but If I call that same function directly from an action event in the GUI bypassing Matlab call, the output is not printed anywhere . I assume it is some sort of IO redirection that has to do with the thread that is executing the action event.
I have a very annoying problem now. I think one of my Java functions calls something in Matlab that errors out. All I hear is Matlab dinging with the error beep, but I see no stack trace or error information anywhere. Debugging in Java does not show where the problem is. I wish there was a way to see what is causing this ding. Is there a generiuc log or some console output that Matlab can generate and dump all the io into it even if it is redirected from some other thread? Any thoughts are appreciated.

Réponses (1)

surya venu
surya venu le 15 Avr 2024
Modifié(e) : surya venu le 15 Avr 2024
Hi,
You're right, the inconsistency in console output between direct Java calls and those routed through MATLAB can be frustrating. Here are some ways to capture the elusive error information in your scenario:
1. Leverage matlab.exception.JavaException:
  • When calling Java methods from MATLAB using javaMethod, wrap the call in a "try-catch" block.
  • Inside the "catch" block, catch the "matlab.exception.JavaException" class.
  • This exception object contains the original Java stack trace and error message. You can access them using the "message" and "stack" properties of the exception object.
2. Capture Console Output:
  • Use diary function to redirect the console output to a file.
diary('matlab_java_output.txt');
% Your Java method calls here
diary off;
This captures all console output, including potential errors, for later inspection.
3. Debug Within MATLAB:
  • Set breakpoints in the MATLAB code that might be called from Java. This allows you to pause execution and inspect variables when the error occurs.
By catching exceptions, enabling verbose mode, or capturing console output, you should be able to identify the source of the error causing the beep in your MATLAB environment.
Hope it helps.

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by