How to catch warnings?
조회 수: 211 (최근 30일)
이전 댓글 표시
채택된 답변
추가 답변 (1개)
Geoff May
2020년 7월 25일
You could use the lastwarn function to reset, then check the last warning. Granted this might not work if the warning you are interested in gets overwritten by a subsequent warning that you would rather discard.
% reset the lastwarn message and id
lastwarn('', '');
% call the function that might throw a warning
diceyFunction();
% now if a warning was raised, warnMsg and warnId will not be empty.
[warnMsg, warnId] = lastwarn();
% you can check the warning message or id, or just throw the warning as an error if desired
if(isempty(warnId))
noProblem();
else
error(warnMsg, warnId);
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Error Handling에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!