title: Handling two WebException's properly
body: <p>I am trying to handle two different <code>WebException</code>'s properly.</p>
  <p>Basically they are handled after calling <code>WebClient.DownloadFile(string address, string fileName)</code></p>
  <p>AFAIK, so far there are two I have to handle, both <code>WebException</code>'s:</p>
  <ul>
  <li>The remote name could not be resolved (i.e. No network connectivity to access server to download file)</li>
  <li>(404) File not nound (i.e. the file doesn't exist on the server)</li>
  </ul>
  <p>There may be more but this is what I've found most important so far.</p>
  <p>So how should I handle this properly, as they are both <code>WebException</code>'s but I want to handle each case above differently.</p>
  <p>This is what I have so far:</p>
  <pre class="lang-cs prettyprint-override"><code>try
  {
      using (var client = new WebClient())
      {
          client.DownloadFile(&quot;...&quot;);
      }
  }
  catch(InvalidOperationException ioEx)
  {
      if (ioEx is WebException)
      {
          if (ioEx.Message.Contains(&quot;404&quot;)
          {
              //handle 404
          }
          if (ioEx.Message.Contains(&quot;remote name could not&quot;)
          {
              //handle file doesn't exist
          }
      }
  }
  </code></pre>
  <p>As you can see I am checking the message to see what type of <code>WebException</code> it is. I would assume there is a better or a more precise way to do this?</p>