title: Good error handling with file_get_contents
body: <p>I am making use of <a href="http://simplehtmldom.sourceforge.net/" rel="noreferrer">simplehtmldom</a> which has this funciton:</p>
  
  <pre><code>// get html dom form file
  function file_get_html() {
      $dom = new simple_html_dom;
      $args = func_get_args();
      $dom-&gt;load(call_user_func_array('file_get_contents', $args), true);
      return $dom;
  }
  </code></pre>
  
  <p>I use it like so:</p>
  
  <pre><code>$html3 = file_get_html(urlencode(trim("$link")));
  </code></pre>
  
  <p>Sometimes, a URL may just not be valid and I want to handle this. I thought I could use a try and catch but this hasn't worked since it doesn't throw an exception, it just gives a php warning like this:</p>
  
  <pre><code>[06-Aug-2010 19:59:42] PHP Warning:  file_get_contents(http://new.mysite.com/ghs 1/) [&lt;a href='function.file-get-contents'&gt;function.file-get-contents&lt;/a&gt;]: failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found  in /home/example/public_html/other/simple_html_dom.php on line 39
  </code></pre>
  
  <p>Line 39 is in the above code.</p>
  
  <p>How can i correctly handle this error, can I just use a plain <code>if</code>condition, it doesn't look like it returns a boolean.</p>
  
  <p>Thanks all for any help</p>
  
  <h2>Update</h2>
  
  <p>Is this a good solution?</p>
  
  <pre><code>if(fopen(urlencode(trim("$next_url")), 'r')){
  
      $html3 = file_get_html(urlencode(trim("$next_url")));
  
  }else{
      //do other stuff, error_logging
      return false;
  
  }
  </code></pre>