@FunctionalInterface public interface ThrowingSupplier<T> extends Supplier<T>
| Modifier and Type | Method and Description |
|---|---|
default Supplier<T> |
fallbackTo(Supplier<T> fallback)
Returns a
Supplier returning from the given supplier if this supplier throws an exception. |
default Supplier<T> |
fallbackTo(Supplier<T> fallback,
Consumer<Exception> exceptionConsumer)
Returns a
Supplier returning from the given supplier if this supplier throws an exception. |
default T |
get()
Returns a result.
|
T |
getThrowing()
Returns a result.
|
default Supplier<T> |
orReturn(T value)
Returns a
Supplier returning the given value if this supplier throws an exception. |
default Supplier<T> |
orReturn(T value,
Consumer<Exception> exceptionConsumer)
Returns a
Supplier returning the given value if this supplier throws an exception. |
default ThrowingSupplier<T> |
orThrow(Class<? extends RuntimeException> exceptionClass)
Returns a
ThrowingSupplier throwing an exception of the given type if this supplier throws an exception. |
default ThrowingSupplier<T> |
orThrow(Class<? extends RuntimeException> exceptionClass,
String message)
Returns a
ThrowingSupplier throwing an exception of the given type if this supplier throws an exception. |
default ThrowingSupplier<T> |
orTryWith(ThrowingSupplier<? extends T> other)
Returns a
ThrowingSupplier returning from the given supplier if this supplier throws an exception. |
default ThrowingSupplier<T> |
orTryWith(ThrowingSupplier<? extends T> other,
Consumer<Exception> exceptionConsumer)
Returns a
ThrowingSupplier returning from the given supplier if this supplier throws an exception. |
default Supplier<T> fallbackTo(Supplier<T> fallback)
Supplier returning from the given supplier if this supplier throws an exception.IllegalArgumentException - if fallback is nulldefault Supplier<T> fallbackTo(Supplier<T> fallback, Consumer<Exception> exceptionConsumer)
Supplier returning from the given supplier if this supplier throws an exception.IllegalArgumentException - if fallback is nulldefault T get()
UncheckedException.default Supplier<T> orReturn(T value)
Supplier returning the given value if this supplier throws an exception.default Supplier<T> orReturn(T value, Consumer<Exception> exceptionConsumer)
Supplier returning the given value if this supplier throws an exception.default ThrowingSupplier<T> orThrow(Class<? extends RuntimeException> exceptionClass)
ThrowingSupplier throwing an exception of the given type if this supplier throws an exception.
The original exception thrown by this supplier is the cause of the thrown exception.
The exception class must have a constructor accepting a single Throwable as an argument.
IllegalArgumentException - if exceptionClass is nulldefault ThrowingSupplier<T> orThrow(Class<? extends RuntimeException> exceptionClass, String message)
ThrowingSupplier throwing an exception of the given type if this supplier throws an exception.
The original exception thrown by this supplier is the cause of the thrown exception.
The exception class must have a constructor accepting String and Throwable as arguments.
IllegalArgumentException - if exceptionClass is nulldefault ThrowingSupplier<T> orTryWith(ThrowingSupplier<? extends T> other)
ThrowingSupplier returning from the given supplier if this supplier throws an exception.IllegalArgumentException - if other is nulldefault ThrowingSupplier<T> orTryWith(ThrowingSupplier<? extends T> other, Consumer<Exception> exceptionConsumer)
ThrowingSupplier returning from the given supplier if this supplier throws an exception.IllegalArgumentException - if other is null