Stuart’s MATLAB Videos

Watch and Learn

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Reading Web Pages, Part 2: Using try/catch to Handle Errors 2

Posted by Stuart McGarrity,

In the next video in his series on reading web pages, Matt uses a try/catch statement to make his code more robust.

Download the example files used in the video.

2 CommentsOldest to Newest

Yaroslav replied on : 1 of 2
A simple try/catch block is good to catch all possible errors by brute-force, when one doesn't care what went wrong so long as the code continues to run. In the current example—for debugging purposes—it would be better to catch the exceptions, and later watch them to understand what went wrong. For example,
RunMExceptions = []; % an array of MException objects


catch ME,
   disp('Something went wrong. Good thing we have try-catch');

   RunMExceptions = [RunMExceptions; ME]; % store for later use