How to catch warnings?
163 ビュー (過去 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!