CoreTaskExtensionsCatchTException, TResult Method (TaskTResult, PredicateTException, FuncTaskTResult, TException, TaskTResult) |
Namespace: Rackspace.Threading
public static Task<TResult> Catch<TException, TResult>( this Task<TResult> task, Predicate<TException> filter, Func<Task<TResult>, TException, Task<TResult>> handler ) where TException : Exception
Exception | Condition |
---|---|
ArgumentNullException |
If task is . -or- If filter 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) when (filter(ex)) { return await handler(task, ex).ConfigureAwait(false); }
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 handler function is executed synchronously, this method should only be used for lightweight continuation functions. This restriction applies only to handler itself, not to the TaskTResult returned by it. |