title: Handle exception thrown by a task
body: <p>I have a task running a long time operation in WPF:</p>
  
  <pre><code>Task t = Task.Factory.StartNew(() =&gt;
  {
      try
      {
          process(cancelTokenSource.Token, CompressionMethod, OpInfo);
      }
      catch (OperationCanceledException)
      {
          logger.Info("Operation cancelled by the user");
      }
  }, cancelTokenSource.Token);
  
  try
  {
      t.Wait();
  }
  catch (AggregateException ae)
  {
      int i = 0;
  }     
  
  
  private void process(CancellationToken token, CompressionLevel level, OperationInfo info)
  {
      // check hash
      if (ComputeHash)
      {
          logger.Info("HASH CHECKING NOT IMPLEMENTED YET!");
          MessageBox.Show(this,"HASH CHECKING NOT IMPLEMENTED YET!", "WARNING", MessageBoxButton.OK, MessageBoxImage.Warning);
      }
      token.ThrowIfCancellationRequested();
      UserMsgPhase = "Operation finished";
  
      return info;
  }
  </code></pre>
  
  <p>Problem is "MessageBox.Show" throws an exception and it is not captured within "catch (AggregateException ae)". I've been reading about TPL exception handling but I don't understand why it is not catched. Please, could you help me?</p>