title: How to determine a 404 response status when using the HttpClient.GetAsync()
body: <p>I am trying to determine the <code>response</code> returned by <code>HttpClient</code>'s <code>GetAsync</code> method in the case of 404 errors using C# and .NET 4.5.</p>
  
  <p>At present I can only tell that an error has occurred rather than the error's status such as 404 or timeout.</p>
  
  <p>Currently my code my code looks like this:</p>
  
  <pre><code>    static void Main(string[] args)
      {
          dotest("http://error.123");
          Console.ReadLine();
      }
  
      static async void dotest(string url)
      {
          HttpClient client = new HttpClient();
  
          HttpResponseMessage response = new HttpResponseMessage();
  
          try
          {
              response = await client.GetAsync(url);
  
              if (response.IsSuccessStatusCode)
              {
                  Console.WriteLine(response.StatusCode.ToString());
              }
              else
              {
                  // problems handling here
                  string msg = response.IsSuccessStatusCode.ToString();
  
                  throw new Exception(msg);
              }
  
          }
          catch (Exception e)
          {
              // .. and understanding the error here
              Console.WriteLine(  e.ToString()  );                
          }
      }
  </code></pre>
  
  <p>My problem is that I am unable to handle the exception and determine its status and other details of what went wrong.</p>
  
  <p>How would I properly handle the exception and interpret what errors occurred?</p>