dbstop if error not working

조회 수: 21 (최근 30일)
Dylan
Dylan 2023년 10월 24일
댓글: Walter Roberson 2023년 10월 25일
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
Matt J
Matt J 2023년 10월 24일
What happens if you use the Pause On Errors menu option instead of dbstop?
Dylan
Dylan 2023년 10월 24일
That option doesn't seem to have any effect

댓글을 달려면 로그인하십시오.

답변 (2개)

the cyclist
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
Dylan
Dylan 2023년 10월 24일
Ok I see. And just to confirm dbstop if caught error is expected to work in cell mode? That does enter debug mode for me when I do cmd + enter.
Walter Roberson
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
Walter Roberson 2023년 10월 24일
if you are within a try/catch then use
dbstop if caught error
  댓글 수: 3
Walter Roberson
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
Dylan
Dylan 2023년 10월 24일
Thanks.
Any reason why dbstop if caught error would work and not dbstop if error?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Debugging and Analysis에 대해 자세히 알아보기

태그

제품


릴리스

R2023b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by