The end is not the correct method to jump to the next iteration. Actually the continue command would solve this, but in your case no command is enough already:
for i=1:100
try
webread('www.something that could or could not generate an error.com')
catch
end
end
When you read this code in some years, the empty catch branch might look confusing like you've forgotten to program this part. So insert a meaningful comment why this is empty.
In most cases it is useful to display a comment when a try fails, or at least store a message in a protocol or something like this. If e.g. all iterations fail, the code will not perform anything and the user might get doubts about what's going on. In addition there could be a programming error or the inputs of webread might be changed in a future version of Matlab. Then try catch will hide the error message an the user has no chance to detect this. Therefore it is a fair strategy to treat the catch branch as obligatory:
for i=1:100
try
webread('www.something that could or could not generate an error.com')
catch ME
fprintf('WEBREAD without success: %s\n', ME.message);
end
end
EDITED: The command "continue" will jump back to the surrounding for loop without processing the rest of the loop body:
for i=1:100
try
webread('www.something that could or could not generate an error.com')
catch ME
fprintf('WEBREAD without success: %s\n', ME.message);
continue;
end
fprintf("WEBREAD worked successfully\n");
end
Now the success message will not appear in a case of an error. When there is no code behind the try-catch block, the continue has no effect, because there are no commands to be skipped.
Use continue carefully. In a bigger code this command can increase or reduce the readability. It might be "nicer" to move the success message insider the try branch. However, a descriptive comment is the best idea to state the purpose of continue clearly.
Best Answer