title: PHP DOMDocument error handling
body: <p>In my application I am loading xml from url in order to parse it.
  But sometimes this url may not be valid. In this case I need to handle errors.
  I have the following code:</p>
  
  <pre><code>$xdoc = new DOMDocument();
  try{
    $xdoc-&gt;load($url); // This line causes Warning: DOMDocument::load(...)
                       // [domdocument.load]: failed to open stream: 
                       // HTTP request failed! HTTP/1.1 404 Not Found in ...
  } catch (Exception $e) {
    $xdoc = null;
  }
  
  if($xdoc == null){
    // Handle
  } else {
    // Proceed
  }
  </code></pre>
  
  <p>I know I probably doing it wrong, but what's a correct way to handle this kind of exceptions? I don't want to see error messages on my page.</p>
  
  <p>The manual for DOMDocument::load() says: </p>
  
  <blockquote>
    <p>If an empty string is passed as the
    filename  or an empty file is named, a
    warning will be generated. This
    warning is not generated by libxml and
    cannot be handled using libxml's error
    handling functions.</p>
  </blockquote>
  
  <p>But there is no information on how to handle it.</p>
  
  <p>Thanks.</p>