Interface CheckedSupplier<R>
- Type Parameters:
R- the return type
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
-
Method Summary
Modifier and TypeMethodDescriptionget()This method performs the operation that may fail with a CheckedExceptionstatic <R> Supplier<R>safe(CheckedSupplier<R> supplierThatCanFailedWithACheckedException) Wraps aCheckedSupplier(basically a lambda with no arguments that returns a result and which throws a CheckedException) by returning a newSupplierinstance
The returnedSupplier.get()method delegates directly to theget()and catches any thrown checkedException's and rethrows them as aCheckedExceptionRethrownException
Unless you provide a context-message (usingsafe(String, CheckedSupplier)then any caught checkedException's message also becomes theCheckedExceptionRethrownException's message.
AnyRuntimeException's thrown aren't caught and the calling code will receive the originalRuntimeExceptionthrown.
Usage example:
Let's say we have a method calledsomeOperationthat cannot change, but which accepts aSupplierwith the purpose of the calling theSupplier.get().static <R> Supplier<R>safe(String contextMessage, CheckedSupplier<R> supplierThatCanFailedWithACheckedException) Wraps aCheckedSupplier(basically a lambda with no arguments that returns a result and which throws a CheckedException) by returning a newSupplierinstance
The returnedSupplier.get()method delegates directly to theget()and catches any thrown checkedException's and rethrows them as aCheckedExceptionRethrownException
AnyRuntimeException's thrown aren't caught and the calling code will receive the originalRuntimeExceptionthrown.
Usage example:
Let's say we have a method calledsomeOperationthat cannot change, but which accepts aSupplierwith the purpose of the calling theSupplier.get().
-
Method Details
-
get
This method performs the operation that may fail with a CheckedException- Returns:
- the result of performing the operation
- Throws:
Exception- this method can throw both checkedException's as well asRuntimeException's