我试图为一个可能存在也可能不存在的图像文件设置70多个tiff标记。如果我试图设置一个标记,但由于该标记在img文件中不存在而引发异常,我想继续尝试设置剩余的标记,并且我不想按顺序有70个try/catch语句。
有没有办法让它立即继续执行它停止的地方?
例如:不是
try
%matlab code to set tag1
catch ME
%do nothing
end
try
%matlab code to set tag2
catch ME
%do nothing
end
try
%matlab code to set tag3
catch ME
%do nothing
end
而是这个:
try
%Matlab code to set tag1, continue regardless of exception
%Matlab code to set tag2 continue regardless of exception
%Matlab code to set tag3, continue regardless of exception
catch ME
%do nothing skip this tag and execute next line up there ^^^
end
您可以在while
循环中使用try
catch
:
count = 0;
err_count = 0;
while count == err_count
try
% my attmept to understand the tags you asked about
if your_tag_number(count) ~= the_tag_you_want;
error
end
catch ME
err_count = err_count + 1;
end
count = count + 1;
end