Detect errors on GUI
8 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Walter Roberson
on 27 Aug 2018
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 Comments
Walter Roberson
on 28 Aug 2018
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.
More Answers (0)
See Also
Categories
Find more on Interactive Control and Callbacks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!