/// <summary> /// Adds the given <paramref name="binder"/> to this Try's call sequence. /// </summary> public AsyncTry <U> ThenAsync <U>(Func <Task <U> > binder) { TryThrowHelper.VerifyBinderNotNull(binder); var frame = new AsyncTryFrame(TryFrameType.Action, async x => await binder().ConfigureAwait(false), null); return(new AsyncTry <U>(Frames.Add(frame))); }
/// <summary> /// Adds the given <paramref name="binder"/> to this Try's call-sequence. /// </summary> public Try <U> Then <U>(Func <T, U> binder) { TryThrowHelper.VerifyBinderNotNull(binder); var frame = new SyncTryFrame(TryFrameType.Action, x => binder((T)x), null); return(new Try <U>(Frames.Add(frame))); }
/// <summary> /// Adds the given <paramref name="binder"/> to this Try's call sequence. /// </summary> public AsyncTry <U> Then <U>(Func <U> binder) { TryThrowHelper.VerifyBinderNotNull(binder); var frame = new AsyncTryFrame(TryFrameType.Action, async x => binder(), null); return(new AsyncTry <U>(Frames.Add(frame))); }
/// <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)))); }
/// <summary> /// Adds the given <paramref name="binder"/> to this Try's call-sequence. /// </summary> public AsyncTry <U> ThenAsync <U>(Func <T, Task <U> > binder) { TryThrowHelper.VerifyBinderNotNull(binder); var asyncFrames = Frames .ToAsync() .Add(new AsyncTryFrame(TryFrameType.Action, async x => await binder((T)x).ConfigureAwait(false), null)); return(new AsyncTry <U>(asyncFrames)); }
/// <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)))); }
/// <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)))); }
/// <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)))); }