title: How to make a transparent ContinueWith callback which forwards the task completion information?
body: <p>I'm having a <code>Task</code> with a <code>ContinueWith</code> callback. However this is in a separate function which returns the <code>Task</code>, so the caller can optionally add more <code>ContinueWith</code> callbacks or do whatever he wants. I need a way to make this first <code>ContinueWith</code> callback transparent, so that it passes forward the result (not hard) and also the <code>Exception</code> property (this seems to be harder).</p>
  
  <p>If I rethrow the exception I have an issue if the caller doesn't add another <code>ContinueWith</code> callback which would handle it, and it will fall out unhandled to the outer space which I want to avoid.</p>
  
  <p>On the other hand, I don't know how elso I could add the existing <code>Exception</code> to the current task without throwing it.</p>
  
  <p>Here is some sample code.</p>
  
  <pre><code>Task.Factory.StartNew(() =&gt; {
    throw new Exception("test");
  }).ContinueWith(t =&gt; {
    // this is my general handler
    MyExceptionHandler.Handle(t.Exception);
    // etc...
    // HERE set the Exception for the current task to forward it
    return t.Result; // result forwarded
  }).ContinueWith(t =&gt; {
    // this MIGHT be appended by consumer code
    if (t.Exception) // HERE I would like to see the exception which might have been thrown be the original task.
    // do whatever ...
  });
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I've actually noticed that the <code>Exception</code> does get propagated, but it gets rewrapped into a new <code>AggregateException</code>.</p>