Exemplo 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))));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Adds the given <paramref name="exceptionHandler"/> for exceptions assignable to type
        /// <typeparamref name="TException"/> to this Try's call sequence.
        /// </summary>
        public Try <T> Catch <TException>(Func <TException, T> exceptionHandler) where TException : Exception
        {
            TryThrowHelper.VerifyExceptionHandlerNotNull(exceptionHandler);

            var clause = new SyncCatchClause(
                ex => exceptionHandler((TException)ex),
                typeof(TException));

            return(new Try <T>(Frames.Add(new SyncTryFrame(TryFrameType.CatchClause, null, clause))));
        }
Exemplo 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> 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))));
        }
Exemplo n.º 4
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))));
        }