Interface ThrowingSupplier<T>
- Type Parameters:
- T- the type of results supplied by this supplier
- All Superinterfaces:
- Supplier<T>
- All Known Subinterfaces:
- InstanceSupplier<T>
- All Known Implementing Classes:
- BeanInstanceSupplier
A 
Supplier that allows invocation of code that throws a checked
 exception.- Since:
- 6.0
- Author:
- Stephane Nicoll, Phillip Webb
- 
Method SummaryModifier and TypeMethodDescriptiondefault Tget()DefaultSupplier.get()that wraps any thrown checked exceptions (by default in aRuntimeException).default Tget(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 create aThrowingSupplierwhere theget()method wraps any checked exception thrown by the supplied lambda expression or method reference.static <T> ThrowingSupplier<T>of(ThrowingSupplier<T> supplier, BiFunction<String, Exception, RuntimeException> exceptionWrapper) Lambda friendly convenience method that can be used to createThrowingSupplierwhere theget()method wraps any thrown checked exceptions using the givenexceptionWrapper.default ThrowingSupplier<T>throwing(BiFunction<String, Exception, RuntimeException> exceptionWrapper) Return a newThrowingSupplierwhere theget()method wraps any thrown checked exceptions using the givenexceptionWrapper.
- 
Method Details- 
getWithExceptionGets a result, possibly throwing a checked exception.- Returns:
- a result
- Throws:
- Exception- on error
 
- 
getDefaultSupplier.get()that wraps any thrown checked exceptions (by default in aRuntimeException).
- 
getGets a result, wrapping any thrown checked exceptions using the givenexceptionWrapper.- Parameters:
- exceptionWrapper-- BiFunctionthat wraps the given message and checked exception into a runtime exception
- Returns:
- a result
 
- 
throwingdefault ThrowingSupplier<T> throwing(BiFunction<String, Exception, RuntimeException> exceptionWrapper) Return a newThrowingSupplierwhere theget()method wraps any thrown checked exceptions using the givenexceptionWrapper.- Parameters:
- exceptionWrapper-- BiFunctionthat wraps the given message and checked exception into a runtime exception
- Returns:
- the replacement ThrowingSupplierinstance
 
- 
ofLambda friendly convenience method that can be used to create aThrowingSupplierwhere theget()method wraps any checked exception thrown by the supplied lambda expression or method reference.This method can be especially useful when working with method references. It allows you to easily convert a method that throws a checked exception into an instance compatible with a regular Supplier.For example: optional.orElseGet(ThrowingSupplier.of(Example::methodThatCanThrowCheckedException)); - Type Parameters:
- T- the type of results supplied by this supplier
- Parameters:
- supplier- the source supplier
- Returns:
- a new ThrowingSupplierinstance
 
- 
ofstatic <T> ThrowingSupplier<T> of(ThrowingSupplier<T> supplier, BiFunction<String, Exception, RuntimeException> exceptionWrapper) Lambda friendly convenience method that can be used to createThrowingSupplierwhere theget()method wraps any thrown checked exceptions using the givenexceptionWrapper.This method can be especially useful when working with method references. It allows you to easily convert a method that throws a checked exception into an instance compatible with a regular Supplier.For example: optional.orElseGet(ThrowingSupplier.of(Example::methodThatCanThrowCheckedException, IllegalStateException::new)); - Type Parameters:
- T- the type of results supplied by this supplier
- Parameters:
- supplier- the source supplier
- exceptionWrapper- the exception wrapper to use
- Returns:
- a new ThrowingSupplierinstance
 
 
-