title: How to catch 404 WebException for WebClient.DownloadFileAsync
body: <p>This code:</p>
  
  <pre><code>try
  {
    _wcl.DownloadFile(url, currentFileName);
  }
  catch (WebException ex)
  {
    if (ex.Status == WebExceptionStatus.ProtocolError &amp;&amp; ex.Response != null)
      if ((ex.Response as HttpWebResponse).StatusCode == HttpStatusCode.NotFound)
        Console.WriteLine("\r{0} not found.     ", currentFileName);
  }
  </code></pre>
  
  <p>downloads file and informs if 404 error occured.</p>
  
  <p>I decided to download files asynchronously:</p>
  
  <pre><code>try
  {
    _wcl.DownloadFileAsync(new Uri(url), currentFileName);
  }
  catch (WebException ex)
  {
    if (ex.Status == WebExceptionStatus.ProtocolError &amp;&amp; ex.Response != null)
      if ((ex.Response as HttpWebResponse).StatusCode == HttpStatusCode.NotFound)
        Console.WriteLine("\r{0} not found.     ", currentFileName);
  }
  </code></pre>
  
  <p>Now this catch block does not fire if server returns a 404 error and WebClient produces an empty file.</p>