title: How do you handle resources in MATLAB in an exception safe manner? (like "try ... finally")
body: <p>Since there is no finally clause to the try-catch block in MATLAB, I find myself writing lots of code like the following:</p>
  
  <pre><code>fid = fopen(filename);
  if fid==-1
      error('Couldn''t open file');
  end
  try
     line = getl(fid);
  catch ME
     fclose(fid);
     rethrow ME;
  end
  fclose(fid);
  </code></pre>
  
  <p>I find having the fclose function in two places ugly and error prone. </p>
  
  <p>Is there a better way for doing this?</p>