How do I prevent "webread" from terminating execution of my code upon error in MATLAB R2025b?

The "webread" function terminates the execution of my code when encountering web errors such as 404 and 504. How can I suppress this error message and let my program continue on to the next instruction?

 Accepted Answer

In the event of errors such as "404 - 'Not found'" and "504 - 'GATEWAY_TIMEOUT'", "webread" throws an error which causes the currently executing code to terminate. To handle these errors so that they do not terminate code execution, employ a "try/catch" block to implement the desired behavior when the URL fails to return data:
try
% call to webread()
catch
% you can write code here to return an empty string instead or any other desired behavior
end

More Answers (0)

Products

Release

R2025b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!