title: Properly handling HttpClient exceptions within async / await
body: <p>I was hoping somebody could enlighten me a little bit on an issue I am facing in regards to async/await exception handling with HttpClient. I have written some code to illustrate, and it is being excecuted on both a Windows Phone 8 device and the emulator:</p>
  <pre><code>    private async void SearchButton_Click(object sender, EventArgs e)
      {
          try
          {
              HttpClient client = new HttpClient();
              System.Diagnostics.Debug.WriteLine(&quot;BEGIN FAULTY REQUEST:&quot;);
              string response = await client.GetStringAsync(&quot;http://www.ajshdgasjhdgajdhgasjhdgasjdhgasjdhgas.tk/&quot;);
              System.Diagnostics.Debug.WriteLine(&quot;SUCCESS:&quot;);
              System.Diagnostics.Debug.WriteLine(response);
          }
          catch (Exception exception)
          {
              System.Diagnostics.Debug.WriteLine(&quot;CAUGHT EXCEPTION:&quot;);
              System.Diagnostics.Debug.WriteLine(exception);
          }
      }
  </code></pre>
  <p>Tapping the button that invokes this function, produces the following output in the debugger console, the most interesting being the ones in <b>bold</b>:</p>
  <p><em>BEGIN FAULTY REQUEST:</em></p>
  <blockquote>
  <p>An exception of type 'System.Net.WebException' occurred in System.Windows.ni.dll and wasn't handled before a managed/native boundary</p>
  <p>An exception of type 'System.Net.WebException' occurred in System.Windows.ni.dll and wasn't handled before a managed/native boundary</p>
  <p>A first chance exception of type 'System.Net.Http.HttpRequestException' occurred in mscorlib.ni.dll</p>
  <p>An exception of type 'System.Net.Http.HttpRequestException' occurred in mscorlib.ni.dll and wasn't handled before a managed/native boundary</p>
  </blockquote>
  <p><em>CAUGHT EXCEPTION:</em></p>
  <blockquote>
  <p>(and here it prints out the HttpRequestException)</p>
  </blockquote>
  <p>Of course I am expecting an error in this case since the URL I am calling is nonsense. What I am not understanding here, is why the debugger reports that the exceptions are not handled, when the output simultaneously reports that the exception is caught. Also, the UI side of the app becomes much less responsive while the output is being printed, indicating that something is probably amiss.</p>
  <p>Is this not the way to handle exceptions when working with async and await? I appreciate any input! Thanks.</p>