CoreTaskExtensionsCatchTException Method (Task, ActionTask, TException) |
Namespace: Rackspace.Threading
public static Task Catch<TException>( this Task task, Action<Task, TException> 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 { await task.ConfigureAwait(false); } catch (TException ex) { 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(Task, FuncTask, TException, Task) instead. |