Is there a way to catch errors with out using try catch statements?
조회 수: 6 (최근 30일)
이전 댓글 표시
Hi,
I have created a GUI and deployed it. It works well but sometimes it gives error but user can't see it. Is there a way to show any kind of error to the user by using message box?
In other words I want to catch all errors with out using try catch statements because I have lots of functions in my program and writing try catch for all of them is time consuming.
댓글 수: 0
채택된 답변
Jan
2014년 1월 12일
No, writing TRY-CATCH blocks is not time-consuming. It is required to catch errors and of course you cannot catch all problems automagically.
A reliable program requires an error handling and at least including the main function should be the absolut minimum.
댓글 수: 0
추가 답변 (1개)
Image Analyst
2014년 1월 12일
No, you need a try catch. You don't have to have it in each and every single function. If there is an error in a function without one, then it will bubble up to the first calling routine it sees that does have one. So put this in ever function where you want to alert the user to an error:
try
% Your code goes here.
catch ME
% You get here if there was an error in this function
% or some function this function called that was unhandled.
errorMessage = sprintf('Error in function %s() at line %d.\n\nError Message:\n%s', ...
ME.stack(1).name, ME.stack(1).line, ME.message);
fprint('%s\n', errorMessage);
uiwait(warndlg(errorMessage));
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!