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 CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by