title: Good pattern for exception handling when using async calls
body: <p>I want to consume an Web API and I see many people recommending <code>System.Net.Http.HttpClient</code>. </p>
  
  <p>That's fine... but I have only VS-2010, so I cannot use <code>async/await</code> just yet. Instead, I guess I could use <code>Task&lt;TResult&gt;</code> in combination to <code>ContinueWith</code>. So I tried this piece of code:</p>
  
  <pre><code>var client = new HttpClient();
  client.DefaultRequestHeaders.Accept.Add(
      new MediaTypeWithQualityHeaderValue("application/json"));
  
  client.GetStringAsync(STR_URL_SERVER_API_USERS).ContinueWith(task =&gt;
  {                 
     var usersResultString = task.Result;
     lbUsers.DataSource = JsonConvert.DeserializeObject&lt;List&lt;string&gt;&gt;(usersResultString);
  });
  </code></pre>
  
  <p>My first observation was to realize that it doesn't generate any error if URL is not available, but maybe there will be more errors like this... </p>
  
  <p>So I am trying to find a way to handle exceptions for such async calls (particularly for HttpClient). I noticed that "Task" has <code>IsFaulted</code> property and an <code>AggregateException</code> which maybe could be used, but I am not sure yet how. </p>
  
  <p>Another observation was that <code>GetStringAsync</code> returns <code>Task&lt;string&gt;</code>, but <code>GetAsync</code> returns <code>Task&lt;HttpResponseMessage&gt;</code>. The latter could be maybe more useful, since it presents a <code>StatusCode</code>.</p>
  
  <p>Could you share a pattern on how to use the async calls correctly and handle exceptions in a good way? Basic explanation would be appreciated as well.</p>