public static Task Catch(this Task task,Action<Exception> callback) { return task.ContinueWith<Task>(delegate (Task t) { if (t != null && t.IsFaulted) { AggregateException exception = t.Exception; Trace.TraceError("Catch exception thrown by Task: {0}", new object[] { exception }); callback(exception.InnerException); } return t; }).Unwrap(); }