Esempio n. 1
0
        /// <summary>
        /// Adds the given <paramref name="exceptionHandler"/> for exceptions assignable to type
        /// <typeparamref name="TException"/> to this Try's call sequence.
        /// </summary>
        public AsyncTry <T> CatchAsync <TException>(Func <TException, Task <T> > exceptionHandler) where TException : Exception
        {
            TryThrowHelper.VerifyExceptionHandlerNotNull(exceptionHandler);

            var clause = new AsyncCatchClause(
                async ex => await exceptionHandler((TException)ex).ConfigureAwait(false),
                typeof(TException));

            return(new AsyncTry <T>(Frames.Add(new AsyncTryFrame(TryFrameType.CatchClause, null, clause))));
        }
Esempio n. 2
0
        /// <summary>
        /// Adds the given <paramref name="exceptionHandler"/> for exceptions assignable to type
        /// <paramref name="exceptionType"/> to this Try's call sequence.
        /// </summary>
        public AsyncTry <T> CatchAsync(Type exceptionType, Func <Exception, Task <T> > exceptionHandler)
        {
            TryThrowHelper.VerifyExceptionType(exceptionType);
            TryThrowHelper.VerifyExceptionHandlerNotNull(exceptionHandler);

            var clause = new AsyncCatchClause(
                async ex => await exceptionHandler(ex).ConfigureAwait(false),
                exceptionType);

            return(new AsyncTry <T>(Frames.Add(new AsyncTryFrame(TryFrameType.CatchClause, null, clause))));
        }
Esempio n. 3
0
        /// <summary>
        /// Adds the given <paramref name="exceptionHandler"/> for exceptions assignable to type
        /// <paramref name="exceptionType"/> to this Try's call sequence.
        /// </summary>
        public AsyncTry <T> Catch(Type exceptionType, Func <Exception, T> exceptionHandler)
        {
            TryThrowHelper.VerifyExceptionType(exceptionType);
            TryThrowHelper.VerifyExceptionHandlerNotNull(exceptionHandler);

            var clause = new AsyncCatchClause(
                async ex => exceptionHandler(ex),
                exceptionType);

            return(new AsyncTry <T>(Frames.Add(new AsyncTryFrame(TryFrameType.CatchClause, null, clause))));
        }