title: Proper way of handling exception in task continuewith
body: <p>Please have a look at the following code-</p>
  
  <pre><code>static void Main(string[] args)
  {
      // Get the task.
      var task = Task.Factory.StartNew&lt;int&gt;(() =&gt; { return div(32, 0); });
  
      // For error handling.
      task.ContinueWith(t =&gt; { Console.WriteLine(t.Exception.Message); }, 
          TaskContinuationOptions.OnlyOnFaulted);
  
      // If it succeeded.
      task.ContinueWith(t =&gt; { Console.WriteLine(t.Result); }, 
          TaskContinuationOptions.OnlyOnRanToCompletion);
      Console.ReadKey();
      Console.WriteLine("Hello");
  }
  
  private static int div(int x, int y)
  {
      if (y == 0)
      {
          throw new ArgumentException("y");
      }
      return x / y;
  }
  </code></pre>
  
  <p>If I execute the code in release mode, The output is "One or more errors occurred" and once I hit the "Enter key, "Hello" is also getting displayed. If I run the code in debug mode, the output is same as release mode. But when debugging in IDE, A IDE exception message ("Unhandled exception in user code" ) appears when the control executes the line </p>
  
  <pre><code>throw new ArgumentException("y"); 
  </code></pre>
  
  <p>If I continue from there on, the program does not crash and displays the same output as release mode. Is this proper way to handle exception?</p>