Detect errors on GUI

8 ビュー (過去 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 Center および File ExchangeInteractive Control and Callbacks についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by