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
0 个评论
采纳的回答
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.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!