How can I track warnings while ignoring ones whose state is set to "off"?
1 回表示 (過去 30 日間)
古いコメントを表示
MathWorks Support Team
2020 年 11 月 12 日
回答済み: MathWorks Support Team
2021 年 2 月 22 日
I want to activate a flag when an unexpected warning is raised in my code. I expect a subset of the warnings to be generated by the code and I make use of the commands "warning( 'off', ... )" and "warning( 'on', ...)" to temporarily disable/enable these expected warning statements. I am using the "lastwarn" command to check if at least one unexpected warning had been triggered.
I've discovered that using the command "warning( 'off', warningID )" will only prevent the corresponding warning from being displayed, but it is still tracked and displayed in "lastwarn". How can I keep track of the unexpected warnings while ignoring the expected warnings (temporarily disabled with the 'off' state around validated function calls)?
採用された回答
MathWorks Support Team
2020 年 11 月 12 日
As of now, the best way to do this is using the command "warning('query' , 'last')", which will returns a struct with the warning identifier and state. Unlike "lastwarn", this does not pick up warnings that are turned off. However, note that it will only provide the warning identifier and not the warning message.
Also, this command cannot be reset in a similar fashion as "lastwarn('')". Therefore, if you would like to check if the last warning that was thrown is actually a new warning, you will need to use a dummy warning, such as:
>>warning('Dummy:ID' , '')
0 件のコメント
その他の回答 (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!