Clear Filters
Clear Filters

Throwing errors using NET listeners implemented in a class

2 views (last 30 days)
I'm implementing a .NET listener to run Matlab callbacks on a .NET application whenever certain buttons are clicked. This is done in a class, based on the instructions here:
These callbacks are supposed to throw errors as popups if the input is incorrect, and they use the error() function to do this. However, when I run the callbacks using the listeners, anything thrown using the error() function gets downgraded to a warning, and it prints in the Command Window instead of showing as a popup. It looks like this:
Warning: Error occurred while executing the listener callback for event Click defined for class System.Windows.Forms.Button:
Error using GetCanConfigForm/btnCreateSimFunc_Listener (line 75)
Please enter the CAN Rx Msg function name to create.
I can catch these "warnings" using try-catch & rethrow the errors using errordlg(). This does make a popup, but the OK buttons on the errordlg popups do nothing instead of closing the popup as expected. The X in the top right corner does work to close the popup.
How do I either force error() to throw popups in this context, or fix the errordlg() OK button to close the popup?
(Using Matlab R2019a)

Accepted Answer

Katherine May
Katherine May on 29 Apr 2022
Edited: Katherine May on 29 Apr 2022
I found a fix for the errordlg OK button - I needed to add waitfor():
f = errordlg(errtxt, 'CAN Rx Msg Error');
waitfor(f);
uiwait(f) also works.

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!