title: How to handle exceptions from StorageFile::OpenAsync when URI is bad
body: <p>I have a section of code that correctly load images from http URIs when the URIs are valid but I cannot figure how to catch the exception OpenAsync throws when the URI is invalid (results in 404).</p>
  
  <p>The problem is that when the lambda which contains the call to OpenAsync exits, the exception is thrown; the exception is not thrown while in the try/catch block.</p>
  
  <p>The question is:</p>
  
  <p>What is the correct way to catch the exception thrown by StorageFile::OpenAsync?</p>
  
  <pre><code>auto bm = ref new BitmapImage();
  try {
      Uri^ uri = ref new Uri("http://invaliduri.tumblr.com/avatar/128");
  
      auto task = Concurrency::create_task(CreateStreamedFileFromUriAsync("temp-web-file.png", uri, nullptr));
  
      task.then([] (StorageFile^ file) {
          try {
              return file-&gt;OpenAsync(FileAccessMode::Read);
          } catch (...) {
              // this does not catch the exception because the exception
              //   occurs after this lambda is exitted
          }
      }).then([bm](IRandomAccessStream^ inputStream) {
          try {
              return bm-&gt;SetSourceAsync(inputStream);
          } catch (...) {
              // this does not catch the exception because the exception
              //   occurs before this lambda is entered
          }
      });
  } catch (...) {
      // and obviously this would not catch the exception
  }
  </code></pre>