/** * Recover from failure if and only if the exception is a subclass of the given exception filter. * The recover function will be executed in case of failure. * * @param exception Exception filter. * @param value Recover value. * @param <X> Exception type. * @return This try on success, a new success try from recover or a failure try in case of exception. */ public <X extends Throwable> Value<V> recover(Class<X> exception, V value) { return recoverWith(exception, x -> Try.success(value)); }
/** * Recover from failure. The recover function will be executed in case of failure. * * @param fn Recover function. * @return This try on success, a new success try from recover or a failure try in case of exception. */ public Value<V> recoverWith(Throwing.Function<Throwable, Value<V>> fn) { return recoverWith(Throwable.class, fn); }
/** * Recover from failure if and only if the exception is a subclass of the given exception filter. * The recover function will be executed in case of failure. * * @param exception Exception filter. * @param fn Recover function. * @param <X> Exception type. * @return This try on success, a new success try from recover or a failure try in case of exception. */ public <X extends Throwable> Value<V> recover(Class<X> exception, Throwing.Function<X, V> fn) { return recoverWith(exception, x -> Try.apply(() -> fn.apply(x))); }