Detect errors on GUI

6 次查看(过去 30 天)
HSukas
HSukas 2018-8-27
评论: HSukas 2018-8-31
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.

采纳的回答

Walter Roberson
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
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.
HSukas
HSukas 2018-8-31
Thank you!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by