Interface ThrowingSupplier<T>
- Type Parameters:
T
- the type of results supplied by this supplier
- All Superinterfaces:
Supplier<T>
- All Known Subinterfaces:
InstanceSupplier<T>
A
Supplier
that allows invocation of code that throws a checked
exception.- Since:
- 6.0
- Author:
- Stephane Nicoll, Phillip Webb
-
Method Summary
Modifier and TypeMethodDescriptiondefault T
get()
DefaultSupplier.get()
that wraps any thrown checked exceptions (by default in aRuntimeException
).default T
get
(BiFunction<String, Exception, RuntimeException> exceptionWrapper) Gets a result, wrapping any thrown checked exceptions using the givenexceptionWrapper
.Gets a result, possibly throwing a checked exception.static <T> ThrowingSupplier<T>
of
(ThrowingSupplier<T> supplier) Lambda friendly convenience method that can be used to createThrowingSupplier
where theget()
method wraps any thrown checked exceptions.static <T> ThrowingSupplier<T>
of
(ThrowingSupplier<T> supplier, BiFunction<String, Exception, RuntimeException> exceptionWrapper) Lambda friendly convenience method that can be used to createThrowingSupplier
where theget()
method wraps any thrown checked exceptions using the givenexceptionWrapper
.default ThrowingSupplier<T>
throwing
(BiFunction<String, Exception, RuntimeException> exceptionWrapper) Return a newThrowingSupplier
where theget()
method wraps any thrown checked exceptions using the givenexceptionWrapper
.
-
Method Details
-
getWithException
Gets a result, possibly throwing a checked exception.- Returns:
- a result
- Throws:
Exception
- on error
-
get
DefaultSupplier.get()
that wraps any thrown checked exceptions (by default in aRuntimeException
). -
get
Gets a result, wrapping any thrown checked exceptions using the givenexceptionWrapper
.- Parameters:
exceptionWrapper
-BiFunction
that wraps the given message and checked exception into a runtime exception- Returns:
- a result
-
throwing
default ThrowingSupplier<T> throwing(BiFunction<String, Exception, RuntimeException> exceptionWrapper) Return a newThrowingSupplier
where theget()
method wraps any thrown checked exceptions using the givenexceptionWrapper
.- Parameters:
exceptionWrapper
-BiFunction
that wraps the given message and checked exception into a runtime exception- Returns:
- the replacement
ThrowingSupplier
instance
-
of
Lambda friendly convenience method that can be used to createThrowingSupplier
where theget()
method wraps any thrown checked exceptions.- Type Parameters:
T
- the type of results supplied by this supplier- Parameters:
supplier
- the source supplier- Returns:
- a new
ThrowingSupplier
instance
-
of
static <T> ThrowingSupplier<T> of(ThrowingSupplier<T> supplier, BiFunction<String, Exception, RuntimeException> exceptionWrapper) Lambda friendly convenience method that can be used to createThrowingSupplier
where theget()
method wraps any thrown checked exceptions using the givenexceptionWrapper
.- Type Parameters:
T
- the type of results supplied by this supplier- Parameters:
supplier
- the source supplierexceptionWrapper
- the exception wrapper to use- Returns:
- a new
ThrowingSupplier
instance
-