public final class Try
extends java.lang.Object
| Modifier and Type | Method | Description |
|---|---|---|
static <R> Either<java.lang.Exception,R> |
either(CheckedSupplier<R> supplier) |
This method exists to allow usage of
either with checked suppliers
without casting or needing to declare the checked supplier explicitly. |
static <R> Either<java.lang.Exception,R> |
either(java.util.function.Supplier<R> supplier) |
Wraps the call to
get in a try block. |
static <T extends java.lang.AutoCloseable,R> |
trys(CheckedSupplier<T> supplier,
java.util.function.Function<java.lang.Exception,CheckedSupplier<R>> errorHandler,
java.util.function.Function<T,CheckedSupplier<R>> function) |
A method to use auto closing try with resources with lambda parameters.
|
static <T extends java.lang.AutoCloseable,R> |
trys(CheckedSupplier<T> supplier,
java.util.function.Function<T,CheckedSupplier<R>> function) |
Calls the three argument form of this method with an error handler which simply wraps any exception in a
WrappedException. |
public static <T extends java.lang.AutoCloseable,R> CheckedSupplier<R> trys(CheckedSupplier<T> supplier, java.util.function.Function<java.lang.Exception,CheckedSupplier<R>> errorHandler, java.util.function.Function<T,CheckedSupplier<R>> function)
WrappedException is thrown by the supplier or function arguments, it is rethrown. All other
exceptions are passed to the errorHandler argument for handling.T - the supplied AutoCloseable typeR - the supplied result typesupplier - the AutoCloseable suppliererrorHandler - a function to handle exceptions thrown by the supplier or function argumentsfunction - a function that accepts the supplied AutoCloseable type and returns a supplier of the result
typepublic static <T extends java.lang.AutoCloseable,R> CheckedSupplier<R> trys(CheckedSupplier<T> supplier, java.util.function.Function<T,CheckedSupplier<R>> function)
WrappedException.T - the supplied AutoCloseable typeR - the supplied result typesupplier - the AutoCloseable supplierfunction - a function that accepts the supplied AutoCloseable type and returns a supplier of the result typepublic static <R> Either<java.lang.Exception,R> either(java.util.function.Supplier<R> supplier)
get in a try block. Either an exception thrown by the
supplier or the supplied value is returned. If a WrappedException is thrown, its cause is returned.R - the supplied value typesupplier - the value supplierpublic static <R> Either<java.lang.Exception,R> either(CheckedSupplier<R> supplier)
either with checked suppliers
without casting or needing to declare the checked supplier explicitly.R - the supplied value typesupplier - the supplier functionCopyright © 2018. All rights reserved.