title: Unhandled Exception issue in WinRT
body: <p>When I encounter an exception within my code, it will always throw and bubble all the way back to the app.g.i.cs file. It does not matter if I wrap the method causing the exception in a try/catch, it still bubbles back to the App instance.</p>
  
  <p>This is the method I am trying to use:</p>
  
  <pre><code>public static async Task Clear()
  {
      userSessionToken = string.Empty;
  
      var appdata = ApplicationData.Current;
      StorageFile file = await appdata.LocalFolder.GetFileAsync("parseSession");
  
      try
      {
          await file.DeleteAsync(StorageDeleteOption.PermanentDelete);
      }
      catch (FileNotFoundException)
      {
          return;
      }
  }
  </code></pre>
  
  <p>Each time I hit the DeleteAsync method, and the file does not exist, I expect an exception to be thrown and swallowed. Instead, my catch never gets hit. It bubbles all the way up to the app.g.i file.</p>
  
  <pre><code>    public void InitializeComponent()
      {
          if (_contentLoaded)
              return;
  
          _contentLoaded = true;
  #if DEBUG &amp;&amp; !DISABLE_XAML_GENERATED_BINDING_DEBUG_OUTPUT
          DebugSettings.BindingFailed += (sender, args) =&gt;
          {
              global::System.Diagnostics.Debug.WriteLine(args.Message);
          };
  #endif
  #if DEBUG &amp;&amp; !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
          UnhandledException += (sender, e) =&gt;
          {
  // --&gt; THIS Catches the exception &lt;--
              if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();
          };
  #endif
      }
  </code></pre>
  
  <p>I should note that the following:</p>
  
  <pre><code>    try
      {
          await file.DeleteAsync(StorageDeleteOption.PermanentDelete);
      }
      catch (Exception)
      {
          return;
      }
  </code></pre>
  
  <p>has the same result, the catch is never hit.</p>
  
  <p>Can someone please tell me why my exception handlers (it's not just this one, but each one in my app) are not being hit? It's really difficult to properly handle exceptions if my exception handlers are never being provided a chance to handle them. The app is wrote as a Universal Windows 8.1/Windows Phone 8.1 app.</p>
  
  <p>I'm providing the full exception details, however my question is not really what caused the exception, but rather why my catch (even if I just use Exception instead of FileNotFoundException) does not get hit.</p>
  
  <pre><code>-       Exception   {System.IO.FileNotFoundException: The system cannot find the file specified. (Exception from HRESULT: 0x80070002)
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
     at Actions.Services.ParseRest.ParseSession.&lt;Clear&gt;d__e.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
     at Actions.Services.ParseRest.ParseRestUserService.&lt;GetUserAsync&gt;d__a.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
     at Actions.Repositories.User.UserRepository.&lt;GetUserAsync&gt;d__3.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
     at Actions.Apps.WinRT.App.&lt;OnLaunchApplication&gt;d__0.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
     at Microsoft.Practices.Prism.Mvvm.MvvmAppBase.&lt;OnLaunched&gt;d__0.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
     at System.Runtime.CompilerServices.AsyncMethodBuilderCore.&lt;ThrowAsync&gt;b__3(Object state)
     at System.Threading.WinRTSynchronizationContext.Invoker.InvokeCore()}    System.Exception {System.IO.FileNotFoundException}
  </code></pre>
  
  <p>Thanks!</p>