How do I do this without using try/catch?
Afficher commentaires plus anciens
I am using waitbar within Run_pushbutton_Callback (GUIDE GUI):
function Run_pushbutton_Callback(hObject, ~, handles)
try
wb = waitbar(0,'Computing...','Name','MyProgName');
wbch = allchild(wb);
jp = wbch(1).JavaPeer;
jp.setIndeterminate(1);
% call main function
handles.mainfunc(S); % S is structure of variables
close(wb); % close dialog box
catch ME
close(wb); % close dialog box
errorMessage=sprintf('Error in function %s() at line %d.\n\nError Message:\n%s', ...
ME.stack(1).name, ME.stack(1).line, ME.message);
fprintf(2, '%s\n', errorMessage);
uiwait(errordlg(errorMessage)); % error dialog
% rethrow(ME); % rethrow the whole error message in command window (if needed)
end
guidata(hObject, handles);
When mainfunc() throws an error, waitbar still continues blinking - without try/catch. I used try/catch solution to close it. However, Matlab documentation says that the memory optimisation etc is not supported within try/catch: https://www.mathworks.com/help/matlab/matlab_prog/avoid-unnecessary-copies-of-data.html
Also, it looks a bit awkward to use try/catch for entire program.
- How can I close waitbar after error without using try/catch?
- How come that in-place or other optimisation does not work within a function and its subfunctions (not nested) if the function is within try/catch block?
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur App Building dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!