title: TPL Exception handling
body: <p><a href="http://msdn.microsoft.com/en-us/library/dd997415.aspx" rel="noreferrer">http://msdn.microsoft.com/en-us/library/dd997415.aspx</a></p>
  
  <p>Per the article referenced above I am trying to handle exceptions in a continuatin task.  The example I am citing in the above article is this:</p>
  
  <pre><code>var task1 = Task.Factory.StartNew(() =&gt;
  {
      throw new MyCustomException("Task1 faulted.");
  })
  .ContinueWith((t) =&gt;
      {
          Console.WriteLine("I have observed a {0}",
              t.Exception.InnerException.GetType().Name);
      },
      TaskContinuationOptions.OnlyOnFaulted);
  </code></pre>
  
  <p>My code is:</p>
  
  <pre><code>Task&lt;string&gt; task = Task&lt;string&gt;.Factory.StartNew(() =&gt; process.StartTask(this));
  task.ContinueWith(CloseDialog, TaskContinuationOptions.OnlyOnFaulted);
  </code></pre>
  
  <p>In StartTask, I throw an error just like the example.  My expectation is that CloseDialog will execute and I can examine task.Exception within that method as shown by the example.  However when I throw the exception I the code simply stops with an unhandled exception.  Should I be using a try/catch block? If so, where?
  By the way, I want my continuation task (CloseDialog) to ALWAYS run.  I'm just using .OnlyOnFaulted because that is what is shown in the example.</p>