How to make assert() debug break?
Show older comments
I attached my solution. Not sure why it's not the default behavior.
function assert1( b )
if nargin < 1
b = 0;
end
if ~b
disp( 'Assertion failed.' );
dbstack
if 0
dbstop in assert.m at 11;
dbclear in assert.m at 11;
else
ST = dbstack;
if length( ST ) > 1
ST = ST(2);
end
fl = ST.file;
ln = ST.line + 1;
cmd = [ 'dbstop in ' fl ' at ' int2str(ln) ];
eval( cmd )
end
end
end
1 Comment
Jan
on 5 Jul 2022
What is the behavior of your code? It creates a breakpoint in the next line and Matlab will stop there.
What happens in nested functions, functions attached to a script and in anonymous functions?
Accepted Answer
More Answers (0)
Categories
Find more on Debugging and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!