Package ch.powerunit.extensions.exceptions
Functional interface similar to the once from
java.util.function, but
with throws Exception.
The various functional interface provided by this package exposes several dedicated methods :
uncheck()which converts the functional interface to the once fromjava.util.function, having the checked Exception wrapped in aRuntimeException. By default this will be an instance ofWrappedException. An additional methodunchecked(...)is provided to statically create unchecked version of the functional interface.lift()andlifted(...)which converts the functional interface to a version that either return anOptional.empty()or a default value in case of error.ignore()andignored(...)which converts the functional interface to a version that return a default value in case of error.
uncheck... methods) by specifying a Function to compute
the target RuntimeException.
Examples
It is possible to use the methodunchecked to directly create a
functional interface with only runtime exception :
FunctionWithException<String, String, IOException> fonctionThrowingException = ...; Function<String, String> functionThrowingRuntimeException = FunctionWithException.unchecked(fonctionThrowingException);When it is required to thrown a specific
RuntimeException, it is also
possible to specify it :
FunctionWithException<String, String, IOException> fonctionThrowingException = ...;
Function<String, String> functionThrowingRuntimeException =
FunctionWithException.unchecked(
fonctionThrowingException,
IllegalArgumentException::new
);
When the exception should not be thrown in case of error, it is possible to
create a Function with Optional result :
FunctionWithException<String, String, IOException> fonctionThrowingException = ...; Function<String, Optional<String>> functionWithOptionalResult = FunctionWithException.lifted(fonctionThrowingException);
Exception Mapping
By default, the exception are transformed into aRuntimeException
using the WrappedException. This
behaviour can be changed locally (second argument of the unchecked
methods) or globally (by registering default ExceptionMapper.
To do the global configuration, it is required first to create the
ExceptionMapper:
public class MyExceptionMapper implements ExceptionMapper {
public RuntimeException apply(Exception e) {
//Add the code
}
public Class>? extends Exception< targetException() {
return //Add the code;
}
// Optional, to define the order between the ExceptionMapper
public int order() {
return 100;
}
}
Then, the ExceptionMapper must be registered :
module XXX {
requires powerunit.exceptions;
provides ch.powerunit.extensions.exceptions.ExceptionMapper
with ....MyExceptionMapper;
}
- See Also:
java.util.function
-
Interface Summary Interface Description BiConsumerWithException<T,U,E extends Exception> Represents an operation that accepts two input arguments and returns no result and may throw exception.BiFunctionWithException<T,U,R,E extends Exception> Represents a function that accepts two arguments, may thrown exception and produces a result.BinaryOperatorWithException<T,E extends Exception> Represents an operation upon two operands of the same type, that may throw exception, producing a result of the same type as the operands.BiPredicateWithException<T,U,E extends Exception> Represents a predicate (boolean-valued function) of two arguments that may throw exception.BooleanSupplierWithException<E extends Exception> Represents a supplier ofboolean-valued results which may throw exception.ConsumerWithException<T,E extends Exception> Represents an operation that accepts a single input argument, may thrown exception and returns no result.DoubleBinaryOperatorWithException<E extends Exception> Represents an operation upon twodouble-valued operands, may throw exception and producing adouble-valued result.DoubleConsumerWithException<E extends Exception> Represents an operation that accepts a singledouble-valued argument, may throw exception and returns no result.DoubleFunctionWithException<R,E extends Exception> Represents a function that accepts a double-valued argument, may throw exception and produces a result.DoublePredicateWithException<E extends Exception> Represents a predicate (boolean-valued function) of onedouble-valued argument that may throw exception.DoubleSupplierWithException<E extends Exception> Represents a supplier ofdouble-valued results and may throw exception.DoubleToIntFunctionWithException<E extends Exception> Represents a function that accepts a double-valued argument, may throw exception and produces an int-valued result.DoubleToLongFunctionWithException<E extends Exception> Represents a function that accepts a double-valued argument, may throw exception and produces a long-valued result.DoubleUnaryOperatorWithException<E extends Exception> Represents an operation on a singledouble-valued operand that may thrown exception and produces adouble-valued result.ExceptionHandlerSupport<F,L,Z extends ExceptionHandlerSupport<F,L,Z>> Root interface to support global operations related to exception handling.ExceptionMapper Interface to help create mapper function for exception wrapping.FileFilterWithException<E extends Exception> A filter for abstract pathnames and may throw an exception.FilenameFilterWithException<E extends Exception> Instances of classes that implement this interface are used to filter filenames and may throw exception.FunctionWithException<T,R,E extends Exception> Represents a function that accepts one argument, may throw exception and produces a result.IntBinaryOperatorWithException<E extends Exception> Represents an operation upon twoint-valued operands, may thrown exception and producing anint-valued result.IntConsumerWithException<E extends Exception> Represents an operation that accepts a singleint-valued argument, may throw exception and returns no result.IntFunctionWithException<R,E extends Exception> Represents a function that accepts an int-valued argument, may throw exception and produces a result.IntPredicateWithException<E extends Exception> Represents a predicate (boolean-valued function) of oneint-valued argument that may throw exception.IntSupplierWithException<E extends Exception> Represents a supplier ofint-valued results and may throw exception.IntToDoubleFunctionWithException<E extends Exception> Represents a function that accepts an int-valued argument, may throw an exception and produces a double-valued result.IntToLongFunctionWithException<E extends Exception> Represents a function that accepts an int-valued argument, may thrown exception and produces a long-valued result.IntUnaryOperatorWithException<E extends Exception> Represents an operation on a singleint-valued operand that produces anint-valued result and may throws exception.LongBinaryOperatorWithException<E extends Exception> Represents an operation upon twolong-valued operands and producing along-valued result which may throw exception.LongConsumerWithException<E extends Exception> Represents an operation that accepts a singlelong-valued argument, may throw exception and returns no result.LongFunctionWithException<R,E extends Exception> Represents a function that accepts a long-valued argument, may throw exception and produces a result.LongPredicateWithException<E extends Exception> Represents a predicate (boolean-valued function) of onelong-valued argument that may throw exception.LongSupplierWithException<E extends Exception> Represents a supplier oflong-valued results and may throw exception.LongToDoubleFunctionWithException<E extends Exception> Represents a function that accepts a long-valued argument, may throw an exception and produces a double-valued result.LongToIntFunctionWithException<E extends Exception> Represents a function that accepts a long-valued argument, may throw exception and produces an int-valued result.LongUnaryOperatorWithException<E extends Exception> Represents an operation on a singlelong-valued operand, may thrown exception and that produces along-valued result.NoReturnExceptionHandlerSupport<F,S,Z extends NoReturnExceptionHandlerSupport<F,S,Z>> Root interface to support global operations related to exception handling for functional interface without return value.ObjDoubleConsumerWithException<T,E extends Exception> Represents an operation that accepts an object-valued and adouble-valued argument, and returns no result.ObjectInputFilterWithException<E extends Exception> Filter classes, array lengths, and graph metrics during deserialization that may throw exception.ObjectReturnExceptionHandlerSupport<F,L,S,T,Z extends ObjectReturnExceptionHandlerSupport<F,L,S,T,Z>> Root interface to support global operations related to exception handling for functional interface returning Object result.ObjIntConsumerWithException<T,E extends Exception> Represents an operation that accepts an object-valued and aint-valued argument, and returns no result.ObjLongConsumerWithException<T,E extends Exception> Represents an operation that accepts an object-valued and along-valued argument, and returns no result.PathMatcherWithException<E extends Exception> An interface that is implemented by objects that perform match operations on paths and may throw an exception.PredicateWithException<T,E extends Exception> Represents a predicate (boolean-valued function) of one argument and may throw an exception.PrimitiveReturnExceptionHandlerSupport<F,Z extends PrimitiveReturnExceptionHandlerSupport<F,Z>> Root interface to support global operations related to exception handling for functional interface with primitive return value.RunnableWithException<E extends Exception> Represents an operation that accepts no input argument and returns no result and may throw exception.SupplierWithException<T,E extends Exception> Represents a supplier of results that may thrown exception.ToDoubleBiFunctionWithException<T,U,E extends Exception> Represents a function that accepts two arguments, may thrown exception and produces a double-valued result.ToDoubleFunctionWithException<T,E extends Exception> Represents a function that produces a double-valued result, may throw exception.ToIntBiFunctionWithException<T,U,E extends Exception> Represents a function that accepts two arguments and produces an int-valued result.ToIntFunctionWithException<T,E extends Exception> Represents a function that produces an int-valued result and may throw exception.ToLongBiFunctionWithException<T,U,E extends Exception> Represents a function that accepts two arguments, may throw exception and produces a long-valued result.ToLongFunctionWithException<T,E extends Exception> Represents a function that produces a long-valued result and may throw exception.UnaryOperatorWithException<T,E extends Exception> Represents an operation on a single operand that produces a result of the same type as its operand. -
Class Summary Class Description CommonsCollections4Helper This class provides several helper methods for the functional interface of the commons-collections4. -
Exception Summary Exception Description WrappedException RuntimeException to wrap the Exception.