Top Description Methods
org.springframework.util.function

public Interface ThrowingSupplier<T>

extends Supplier<T>
Type Parameters
<T>
the type of results supplied by this supplier
Imports
java.util.function.BiFunction, .Supplier

A Supplier that allows invocation of code that throws a checked exception.
Authors
Stephane Nicoll, Phillip Webb
Since
6.0

Method Summary

Modifier and TypeMethod and Description
public default T
get()

Implements java.util.function.Supplier.get.

Default Supplier#get() that wraps any thrown checked exceptions (by default in a RuntimeException).

public default T

Returns:

a result
get
(BiFunction<String, Exception, RuntimeException>
BiFunction that wraps the given message and checked exception into a runtime exception
exceptionWrapper
)

Gets a result, wrapping any thrown checked exceptions using the given exceptionWrapper.

public T

Returns:

a result
getWithException
()

Gets a result, possibly throwing a checked exception.

public static <
the type of results supplied by this supplier
T
>
ThrowingSupplier<T>

Returns:

a new ThrowingSupplier instance
of
(ThrowingSupplier<T>
the source supplier
supplier
)

Lambda friendly convenience method that can be used to create a ThrowingSupplier where the get() method wraps any checked exception thrown by the supplied lambda expression or method reference.

public static <
the type of results supplied by this supplier
T
>
ThrowingSupplier<T>

Returns:

a new ThrowingSupplier instance
of
(ThrowingSupplier<T>
the source supplier
supplier
,
BiFunction<String, Exception, RuntimeException>
the exception wrapper to use
exceptionWrapper
)

Lambda friendly convenience method that can be used to create ThrowingSupplier where the get() method wraps any thrown checked exceptions using the given exceptionWrapper.

public default ThrowingSupplier<T>

Returns:

the replacement ThrowingSupplier instance
throwing
(BiFunction<String, Exception, RuntimeException>
BiFunction that wraps the given message and checked exception into a runtime exception
exceptionWrapper
)

Return a new ThrowingSupplier where the get() method wraps any thrown checked exceptions using the given exceptionWrapper.

Method Detail

getback to summary
public default T get()

Implements java.util.function.Supplier.get.

Default Supplier#get() that wraps any thrown checked exceptions (by default in a RuntimeException).

Returns:T

Doc from java.util.function.Supplier.get.

a result

Annotations
@Override
See Also
java.util.function.Supplier#get()
getback to summary
public default T get(BiFunction<String, Exception, RuntimeException> exceptionWrapper)

Gets a result, wrapping any thrown checked exceptions using the given exceptionWrapper.

Parameters
exceptionWrapper:BiFunction<String, Exception, RuntimeException>

BiFunction that wraps the given message and checked exception into a runtime exception

Returns:T

a result

getWithExceptionback to summary
public T getWithException() throws Exception

Gets a result, possibly throwing a checked exception.

Returns:T

a result

Exceptions
Exception:
on error
ofback to summary
public static <T> ThrowingSupplier<T> of(ThrowingSupplier<T> supplier)

Lambda friendly convenience method that can be used to create a ThrowingSupplier where the get() 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));
Parameters
<T>
the type of results supplied by this supplier
supplier:ThrowingSupplier<T>

the source supplier

Returns:ThrowingSupplier<T>

a new ThrowingSupplier instance

ofback to summary
public static <T> ThrowingSupplier<T> of(ThrowingSupplier<T> supplier, BiFunction<String, Exception, RuntimeException> exceptionWrapper)

Lambda friendly convenience method that can be used to create ThrowingSupplier where the get() method wraps any thrown checked exceptions using the given exceptionWrapper.

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));
Parameters
<T>
the type of results supplied by this supplier
supplier:ThrowingSupplier<T>

the source supplier

exceptionWrapper:BiFunction<String, Exception, RuntimeException>

the exception wrapper to use

Returns:ThrowingSupplier<T>

a new ThrowingSupplier instance

throwingback to summary
public default ThrowingSupplier<T> throwing(BiFunction<String, Exception, RuntimeException> exceptionWrapper)

Return a new ThrowingSupplier where the get() method wraps any thrown checked exceptions using the given exceptionWrapper.

Parameters
exceptionWrapper:BiFunction<String, Exception, RuntimeException>

BiFunction that wraps the given message and checked exception into a runtime exception

Returns:ThrowingSupplier<T>

the replacement ThrowingSupplier instance