MATLAB: Repeat the iteration with an error using try/catch

catcherrorfor loopiterationnested looptry

I wrote a nested for loop to exexcute a huge number of iterations. However, sometimes an error stops the program. I want to repeat the iEv'th iteration in case an error occurs and then continue to next iteration. Please see below the code and let me know if it should be modified.
for iTcm=1:nTcm
for iScen=1:nScen
for iEv=1:nEv
try
MyProgramHere
catch ME
disp(ME);
fprintf('Retrying the program...\n');
end
end
end
end

Best Answer

Maybe this construct does what you want
while( true )
try
MyProgramHere
break
catch ME
disp(ME);
fprintf('Retrying the program...\n');
end
end