Top Description Methods
org.springframework.util.function

public Interface ThrowingFunction<T, R>

extends Function<T, R>
Annotations
@FunctionalInterface
Type Parameters
<T>
the type of the input to the function
<R>
the type of the result of the function
Imports
java.util.function.BiFunction, .Function

A Function 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 R
apply(T
the function argument
t
)

Implements java.util.function.Function.apply.

Default Function#apply(Object) that wraps any thrown checked exceptions (by default in a RuntimeException).
public default R

Returns:

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

Applies this function to the given argument, wrapping any thrown checked exceptions using the given exceptionWrapper.

public R

Returns:

the function result
applyWithException
(T
the function argument
t
)

Applies this function to the given argument, possibly throwing a checked exception.

public static <
the type of the input to the function
T
,
the type of the result of the function
R
>
ThrowingFunction<T, R>

Returns:

a new ThrowingFunction instance
of
(ThrowingFunction<T, R>
the source function
function
)

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

public static <
the type of the input to the function
T
,
the type of the result of the function
R
>
ThrowingFunction<T, R>

Returns:

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

Lambda friendly convenience method that can be used to create a ThrowingFunction where the apply(Object) method wraps any thrown checked exceptions using the given exceptionWrapper.

public default ThrowingFunction<T, R>

Returns:

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

Return a new ThrowingFunction where the apply(Object) method wraps any thrown checked exceptions using the given exceptionWrapper.

Inherited from java.util.function.Function:
andThencomposeidentity

Method Detail

applyback to summary
public default R apply(T t)

Implements java.util.function.Function.apply.

Default Function#apply(Object) that wraps any thrown checked exceptions (by default in a RuntimeException).

Parameters
t:T

Doc from java.util.function.Function.apply.

the function argument

Returns:R

Doc from java.util.function.Function.apply.

the function result

Annotations
@Override
See Also
java.util.function.Function#apply(java.lang.Object)
applyback to summary
public default R apply(T t, BiFunction<String, Exception, RuntimeException> exceptionWrapper)

Applies this function to the given argument, 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:R

a result

applyWithExceptionback to summary
public R applyWithException(T t) throws Exception

Applies this function to the given argument, possibly throwing a checked exception.

Parameters
t:T

the function argument

Returns:R

the function result

Exceptions
Exception:
on error
ofback to summary
public static <T, R> ThrowingFunction<T, R> of(ThrowingFunction<T, R> function)

Lambda friendly convenience method that can be used to create a ThrowingFunction where the apply(Object) 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 Function.

For example:

stream.map(ThrowingFunction.of(Example::methodThatCanThrowCheckedException));
Parameters
<T>
the type of the input to the function
<R>
the type of the result of the function
function:ThrowingFunction<T, R>

the source function

Returns:ThrowingFunction<T, R>

a new ThrowingFunction instance

ofback to summary
public static <T, R> ThrowingFunction<T, R> of(ThrowingFunction<T, R> function, BiFunction<String, Exception, RuntimeException> exceptionWrapper)

Lambda friendly convenience method that can be used to create a ThrowingFunction where the apply(Object) 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 Function.

For example:

stream.map(ThrowingFunction.of(Example::methodThatCanThrowCheckedException, IllegalStateException::new));
Parameters
<T>
the type of the input to the function
<R>
the type of the result of the function
function:ThrowingFunction<T, R>

the source function

exceptionWrapper:BiFunction<String, Exception, RuntimeException>

the exception wrapper to use

Returns:ThrowingFunction<T, R>

a new ThrowingFunction instance

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

Return a new ThrowingFunction where the apply(Object) 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:ThrowingFunction<T, R>

the replacement ThrowingFunction instance