It is now possible to catch warnings. I am using R2010b where this works, I don't know if it works on any earlier versions than that.
The following code
1) gets a directory listing of the current directory,
2) finds all files that fit a certain name pattern
3) changes the warning msgID MATLAB:DELETE:Permission into an 'error' instead of a warning
4) deletes files in a try-catch block, and catches the files that can't be deleted because of this warning (now treated as an error) condition.
5) finally reverts this msgID back to its old state.
Without setting the state of this msg_id to 'error' the catch does not catch it.
ls = dir;
Ils = find(strncmp('BatInfoDoc',{ls.name},length('BatInfoDoc')));
s = warning('error','MATLAB:DELETE:Permission');
if length(Ils)>3
for I=Ils(1:end-3)
try
delete(ls(I).name);
catch exception
fprintf('Can''t delete %s\n',ls(I).name);
end
end
end
warning(s);
Post by Walter RobersonPost by o***@gmail.comIs it possible to catch warnings like "matrix is close to singular" in
M files? Thanks.
No.
However, if you have places where you expect there might be
warnings, you can test lastwarn and use error(lastwarn) if
you want to force an error to be raised (to be caught by try/catch
block presumably.)
--
"History is a pile of debris" -- Laurie Anderson