In our System.Web.Http.WebHost.HttpControllerHandler.EndProcessRequest(), we will rethrow some exception if task is fauled or cancelled. Unfortunately, this rethrow hides the original exception stack. We should consider preserving it, or at least trace it out.
/// <summary>
/// Provides an asynchronous process End method when the process ends.
/// </summary>
/// <param name="result">An <see cref="T:System.IAsyncResult"/> that contains information about the status of the process.</param>
protected virtual void EndProcessRequest(IAsyncResult result)
{
TaskWrapperAsyncResult asyncResult = (TaskWrapperAsyncResult)result;
Contract.Assert(asyncResult != null);
Task task = asyncResult.Task;
// Check task result and unwrap any exceptions
if (task.IsCanceled)
{
throw Error.OperationCanceled();
}
else if (task.IsFaulted)
{
throw task.Exception.GetBaseException();
}
}
/// <summary>
/// Provides an asynchronous process End method when the process ends.
/// </summary>
/// <param name="result">An <see cref="T:System.IAsyncResult"/> that contains information about the status of the process.</param>
protected virtual void EndProcessRequest(IAsyncResult result)
{
TaskWrapperAsyncResult asyncResult = (TaskWrapperAsyncResult)result;
Contract.Assert(asyncResult != null);
Task task = asyncResult.Task;
// Check task result and unwrap any exceptions
if (task.IsCanceled)
{
throw Error.OperationCanceled();
}
else if (task.IsFaulted)
{
throw task.Exception.GetBaseException();
}
}