Interface ThrowingSupplier<T,X extends Throwable>
- Type Parameters:
T- the type of results supplied by this supplierX- the type of the exception thrown by the function
- All Superinterfaces:
Supplier<T>
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
An extension of
Supplier allowing throwing calls in its body.-
Method Summary
Modifier and TypeMethodDescriptiondefault Tget()Gets a result.static <T,@Any X extends Throwable>
@NotNull ThrowingSupplier<T,X> returning(T value) Creates throwing supplier which always returns the provided value.static <@Any T,X extends Throwable>
@NotNull ThrowingSupplier<T,X> Creates a throwing supplier which always throws an exception produced by using the factory.
-
Method Details
-
getChecked
Gets a result.- Returns:
- a result
- Throws:
X- if an exception happens
-
get
-
returning
Creates throwing supplier which always returns the provided value.- Type Parameters:
T- the type of the supplied resultX- any formal type of the (never thrown) exception- Parameters:
value- the value always returned by this factory- Returns:
- created throwing supplier
-
throwing
@NotNull static <@Any T,X extends Throwable> @NotNull ThrowingSupplier<T,X> throwing(@NonNull @NonNull Supplier<? extends @NotNull X> exceptionFactory) Creates a throwing supplier which always throws an exception produced by using the factory.- Type Parameters:
T- any formal type of the (never returned) valueX- the type of the exception thrown by the function- Parameters:
exceptionFactory- factory used for creation of the exception- Returns:
- throwing runnable which always throws
Xby creating it via the provided factory - Throws:
NullPointerException- ifexceptionFactoryisnull- API note
- if the
exceptionFactoryproducesnullthenNullPointerExceptionwill be thrown when attempting to throw the expected exception
-