dbstop if error not working
29 ビュー (過去 30 日間)
古いコメントを表示
I would like matlab to enter debug mode when there is an error by calling dbstop if error, but it's not working.
In the following code for example, Matlab errors as expected but it doesn't enter debug mode. Are there any settings I should check? I don't see a debug menu.
dbstop if error
ferror123()
function ferror123() % this function errors
x = [];
x(4);
end
2 件のコメント
回答 (2 件)
the cyclist
2023 年 10 月 24 日
ferror is the name of a built-in MATLAB function (which the debugger cannot open into). I expect it is being called, rather than your function.
Try renaming your function, and I expect the debugger will be triggered.
8 件のコメント
Walter Roberson
2023 年 10 月 25 日
Yes, dbstop if caught error is expected to work in cell mode -- but any line numbers reported might look strange.
Walter Roberson
2023 年 10 月 24 日
if you are within a try/catch then use
dbstop if caught error
3 件のコメント
Walter Roberson
2023 年 10 月 24 日
dbstop if error is only for unhandled errors when no try/catch is in effect.
dbstop if caught error is for all error cases... including "expected" errors.
What I mean by expected errors is that in order to deal with compatibility issues or with the possibility of hardware that might or might not be present, it is not uncommon for internal routines to use try/catch protecting a statement that is needed if conditions are right but can be skipped if they are not right.
As an example sometimes it is easier to code
try
delete(OldObject);
catch ME
end
rather than to code testing to see if OldObject exists and is in a deletable state
参考
カテゴリ
Help Center および File Exchange で Debugging and Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!