indicating an error occurred using application in MATLAB app creator

1 次查看(过去 30 天)
hi
i am trying to build a standalone app that writes and process data. i want to use the lamp object in order to indicate if the process has run smoothly or if an error has occured. couldnt find a way to do it because it just breaks the code like a return function.
hope you could help me

采纳的回答

Walter Roberson
Walter Roberson 2023-4-4
In the case where an "error" occurs in the sense of trying to assign the wrong number of values, or subscript out of range, then such things can mostly be caught by using try, catch
But in the case where the program is smoothly detecting that it cannot handle something (for example user entered a negative number and the code tests for that before using the number), and the code uses return or equivalent, then there might not always be a smooth way to handle the situation.
If you have the cooperation of the code, then the code can set a shared status value to reflect its success. Or with cooperation, the driver code could set the lamp indicating that a problem has occurred, and then when the called code detects that everything has gone smoothly, before returning it could clear the lamp, indirectly signalling success.
If you do not have the cooperation of the code, you need to use indirect methods, such as knowing that a successful execution would have added an additional file, so the monitor code could take a record of which files existed before calling the code, then call the code, and afterwards check to see which files are present: if there is a new file then deduce that the code worked. (The deduction is a bit fragile unless the code was careful about how it handled files.)
There is no built-in way to ask whether a function call "succeeded" when the call did not generate an error. Consider for example,
function test
s = input('enter something', 's');
if ismember('t', s)
disp('Bhuannaich!');
else
disp('Kegagalan!');
end
end
There is clearly no reasonable way that you could expect MATLAB to parse the text being displayed and find translations into some convenient language (such as Esperanto) and do a sentiment analysis in order to figure out which of the outcomes is failure and which is success.
  1 个评论
Dolev
Dolev 2023-4-4
thank you very much for the detailed answer, i have figured as much after few days of looking the matter up so i have only done and indication for if the code succeding

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Downloads 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by