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 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.º 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 Try <T> Catch(Type exceptionType, Func <Exception, T> exceptionHandler)
        {
            TryThrowHelper.VerifyExceptionType(exceptionType);
            TryThrowHelper.VerifyExceptionHandlerNotNull(exceptionHandler);

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

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