What happens if a MATLAB executable (GUI for example) runs into an erro while running?

Hello,
If I were to compile an executable (GUI for example) which asks the user to load a file, then, when processing the data, MATLAB receives an error, what happens to the executable?
So, for example, let's say you have a GUI (compiled into an exe) which opens an excel sheet, and adds the 3rd and 4th numbers, what happens if the 4th number doesn't exist (or it is a string?)
Does the whole executable file just shut down? Or does it keep trying to run?
Thank you

 Réponse acceptée

Any uncaught error will result in shutdown. If that is not what you want then be sure to put in protective tests, test results of operations to be sure they succeeded, and use try/catch when appropriate.

4 commentaires

For example
function out = snafu(inputVariable)
out = []; % Initialize
try
% Some code which may throw an exception.
catch ME
errorMessage = sprintf('Error in function %s() at line %d.\n\nError Message:\n%s', ...
ME.stack(1).name, ME.stack(1).line, ME.message);
uiwait(warndlg(errorMessage));
end
The way I deal with it now is:
if (condition causing error)
warndlg('Error Message', 'Error Title')
return
end
Is that a reasonable way of doing it?
Might be. Depends on whether the function needs to return a value, and depends on whether any function relies upon actions having been taken that would be skipped if you return early.
That's not so good. You have to know, anticipate, and have an if for that condition. But what if it's something you didn't anticipate? You're not going to catch it and your program will abruptly terminate. Is there any reason why you chose not to follow my recommendation of using try/catch and uiwait()?

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by