CoreTaskExtensionsCatchTException, TResult Method (TaskTResult, FuncTaskTResult, TException, TResult) |
Namespace: Rackspace.Threading
public static Task<TResult> Catch<TException, TResult>( this Task<TResult> task, Func<Task<TResult>, TException, TResult> handler ) where TException : Exception
Exception | Condition |
---|---|
ArgumentNullException |
If task is . -or- If handler is . |
This code implements support for the following construct without requiring the use of /.
try { return await task.ConfigureAwait(false); } catch (TException ex) { return handler(task, ex); }
This method is capable of handling Canceled antecedent tasks when TException is assignable from TaskCanceledException.
This method ensures that exception information provided by a faulted or canceled task is not wrapped in an additional AggregateException.
Notes to Callers |
---|
Since the continuation is executed synchronously, this method should only be used for lightweight exception handler methods. For non-trivial exception handlers, use a Task for the exception handling operation and call CatchTException, TResult(TaskTResult, FuncTaskTResult, TException, TaskTResult) instead. |