70-483 question 43 discussion


You use the Task.Run() method to launch a long-running data processing operation. The
data processing operation often fails in times of heavy network congestion.
If the data processing operation fails, a second operation must clean up any results of the
first operation.
You need to ensure that the second operation is invoked only if the data processing
operation throws an unhandled exception.
What should you do?

  • A. Create a task within the operation, and set the Task.StartOnError property to true.
  • B. Create a TaskFactory object and call the ContinueWhenAll() method of the object.
  • C. Create a task by calling the Task.ContinueWith() method.
  • D. Use the TaskScheduler class to create a task and call the TryExecuteTask() method on the class.
Created 9 months, 3 weeks ago by hopsing600


I just don't see how this is correct. In essence, the explanation says that the second task will always run. Because the first will either complete, fault out, or be canceled. But the question directions state that the second task is only to run if the data processing operation throws an unhandled exception. The word "only" should not be in the question as the answer shows that it's not what was intended.


Agree. C is 'most right' answer. In order to be completely right it must use the ContinueWith method accepting an TaskContinuationOptions, and use TaskContinuationOptions.OnlyOnFaulted. https://msdn.microsoft.com/en-us/library/dd321576(v=vs.110).aspx


@Hopsing600: In production code you would add an if check inside the second task whether the first task completed successfully and skip the remaining execution of the second task. So the correct answer to this very questions is the one provided.