Interface ThrowingFunction<T,R> 
- Type Parameters:
- T- the type of the input to the function
- R- the type of the result of the function
- All Superinterfaces:
- Function<T,- R> 
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
A 
Function that allows invocation of code that throws a checked
 exception.- Since:
- 6.0
- Author:
- Stephane Nicoll, Phillip Webb
- 
Method SummaryModifier and TypeMethodDescriptiondefault RDefaultFunction.apply(Object)that wraps any thrown checked exceptions (by default in aRuntimeException).default Rapply(T t, BiFunction<String, Exception, RuntimeException> exceptionWrapper) Applies this function to the given argument, wrapping any thrown checked exceptions using the givenexceptionWrapper.Applies this function to the given argument, possibly throwing a checked exception.static <T,R> ThrowingFunction <T, R> of(ThrowingFunction<T, R> function) Lambda friendly convenience method that can be used to create aThrowingFunctionwhere theapply(Object)method wraps any checked exception thrown by the supplied lambda expression or method reference.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 aThrowingFunctionwhere theapply(Object)method wraps any thrown checked exceptions using the givenexceptionWrapper.default ThrowingFunction<T, R> throwing(BiFunction<String, Exception, RuntimeException> exceptionWrapper) Return a newThrowingFunctionwhere theapply(Object)method wraps any thrown checked exceptions using the givenexceptionWrapper.
- 
Method Details- 
applyWithException
- 
applyDefaultFunction.apply(Object)that wraps any thrown checked exceptions (by default in aRuntimeException).
- 
applyApplies this function to the given argument, 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 ThrowingFunction<T,R> throwing(BiFunction<String, Exception, RuntimeException> exceptionWrapper) Return a newThrowingFunctionwhere theapply(Object)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 ThrowingFunctioninstance
 
- 
ofLambda friendly convenience method that can be used to create aThrowingFunctionwhere theapply(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)); - Type Parameters:
- T- the type of the input to the function
- R- the type of the result of the function
- Parameters:
- function- the source function
- Returns:
- a new ThrowingFunctioninstance
 
- 
ofstatic <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 aThrowingFunctionwhere theapply(Object)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 Function.For example: stream.map(ThrowingFunction.of(Example::methodThatCanThrowCheckedException, IllegalStateException::new)); - Type Parameters:
- T- the type of the input to the function
- R- the type of the result of the function
- Parameters:
- function- the source function
- exceptionWrapper- the exception wrapper to use
- Returns:
- a new ThrowingFunctioninstance
 
 
-