Detect errors on GUI
6 次查看(过去 30 天)
显示 更早的评论
Hello, I want to make an .exe program using guide. I designed everything.
I want to detect the errors on my code because of the input values. For example for the input value if I input an absurd value (high or low) it gives "Index exceeds matrix dimensions" error on the command window. Now i can see that. But when i create .exe how can I understand the error? Is it possible?
Or, if I get an any kind of error, how can i write "NaN" or "0" to the results section (edit texts).
Thank in advance.
0 个评论
采纳的回答
Walter Roberson
2018-8-27
You should be coding in such a way that you never get those index errors: your code should be testing the user input range or calculated range before doing the indexing.
In the meantime, you should be putting try/catch clauses in your code to detect and display errors that do occur.
try
output = myfunction();
catch ME
output = nan;
end
3 个评论
Walter Roberson
2018-8-28
At the moment, you have some code that is the approximate form
output = myfunction();
or
... series of statements
output = whatever result
but the function myfunction() or the series of statements can fail (because you are not checking your results properly before indexing.)
You can protect against the failure by rewriting your code into the form
try
output = myfunction();
catch ME
output = nan;
end
or
try
... series of statements
output = whatever result
catch ME
output = nan;
end
as appropriate.
You can put try/catch blocks around any series of statements or function calls that might fail with an error() and where you want to have the error smoothly caught instead of causing the program to end.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!