Exemplo n.º 1
0
        public static Task Catch(this Task parent, Action <AggregateException> action)
        {
            var stackTrace = new StackTrace();

            return(parent.ContinueWith(task =>
            {
                if (task.IsFaulted == false)
                {
                    return;
                }

                var ex = task.Exception.ExtractSingleInnerException();
                Execute.OnTheUI(() => ErrorPresenter.Show(ex, stackTrace))
                .ContinueWith(_ => action(task.Exception));
            }));
        }
Exemplo n.º 2
0
        public static Task <TResult> Catch <TResult>(this Task <TResult> parent, Action <AggregateException> action)
        {
            var stackTrace = new StackTrace();

            return(parent.ContinueWith(task =>
            {
                if (task.IsFaulted == false)
                {
                    return task;
                }

                var ex = task.Exception.ExtractSingleInnerException();
                if (ErrorHandler.Handle(ex) == false)
                {
                    Execute.OnTheUI(() => ErrorPresenter.Show(ex, stackTrace))
                    .ContinueWith(_ => action(task.Exception));
                }
                return task;
            }).Unwrap());
        }