Interface ExceptionHandlerSupport<F,L,Z extends ExceptionHandlerSupport<F,L,Z>>
-
- Type Parameters:
F- the type of the java standard functional interface. For example,Function<T,R>.L- the type of the lifted functional interface. For example,Function<T,Optional<R>>.Z- the type of the interface it self.
- All Known Subinterfaces:
BiConsumerWithException<T,U,E>,BiFunctionWithException<T,U,R,E>,BinaryOperatorWithException<T,E>,BiPredicateWithException<T,U,E>,BooleanSupplierWithException<E>,ConsumerWithException<T,E>,DoubleBinaryOperatorWithException<E>,DoubleConsumerWithException<E>,DoubleFunctionWithException<R,E>,DoublePredicateWithException<E>,DoubleSupplierWithException<E>,DoubleToIntFunctionWithException<E>,DoubleToLongFunctionWithException<E>,DoubleUnaryOperatorWithException<E>,FileFilterWithException<E>,FilenameFilterWithException<E>,FunctionWithException<T,R,E>,IntBinaryOperatorWithException<E>,IntConsumerWithException<E>,IntFunctionWithException<R,E>,IntPredicateWithException<E>,IntSupplierWithException<E>,IntToDoubleFunctionWithException<E>,IntToLongFunctionWithException<E>,IntUnaryOperatorWithException<E>,LongBinaryOperatorWithException<E>,LongConsumerWithException<E>,LongFunctionWithException<R,E>,LongPredicateWithException<E>,LongSupplierWithException<E>,LongToDoubleFunctionWithException<E>,LongToIntFunctionWithException<E>,LongUnaryOperatorWithException<E>,NoReturnExceptionHandlerSupport<F,S,Z>,ObjDoubleConsumerWithException<T,E>,ObjectInputFilterWithException<E>,ObjectReturnExceptionHandlerSupport<F,L,S,T,Z>,ObjIntConsumerWithException<T,E>,ObjLongConsumerWithException<T,E>,PathMatcherWithException<E>,PredicateWithException<T,E>,PrimitiveReturnExceptionHandlerSupport<F,Z>,RunnableWithException<E>,SupplierWithException<T,E>,ToDoubleBiFunctionWithException<T,U,E>,ToDoubleFunctionWithException<T,E>,ToIntBiFunctionWithException<T,U,E>,ToIntFunctionWithException<T,E>,ToLongBiFunctionWithException<T,U,E>,ToLongFunctionWithException<T,E>,UnaryOperatorWithException<T,E>
public interface ExceptionHandlerSupport<F,L,Z extends ExceptionHandlerSupport<F,L,Z>>
Root interface to support global operations related to exception handling.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default Zdocumented(Supplier<String> toString)Add atoStringmethod to the existing interface based on the receivedSupplier.default Function<Exception,RuntimeException>exceptionMapper()Mapping operation to convert the exception that may be thrown during execution toRuntimeException.Fignore()Converts this functional interface to the corresponding java standard functional interface returning a default value in case of error.Llift()Converts this functional interface to a lifted one.Funcheck()Converts this functional interface to the corresponding one in java and wrap exception usingexceptionMapper().
-
-
-
Method Detail
-
exceptionMapper
default Function<Exception,RuntimeException> exceptionMapper()
Mapping operation to convert the exception that may be thrown during execution toRuntimeException.The default mapper function may be changed by :
- Using the second argument of the various
uncheckedmethods. This override only the current interface. - By defining global
ExceptionMapper, using the module syntax :provides ch.powerunit.extensions.exceptions.ExceptionMapper with XXX
- Returns:
- the mapping function, which is by default constructing
WrappedException. - See Also:
WrappedException
- Using the second argument of the various
-
uncheck
F uncheck()
Converts this functional interface to the corresponding one in java and wrap exception usingexceptionMapper().Conceptually, the exception encapsulation is done in the following way :
(xxx) -> { try { // do the underlying functional interface action and return result if // applicable } catch (Exception e) { throw new exceptionMapper().apply(e); } }
-
lift
L lift()
Converts this functional interface to a lifted one. A lifted version may or may not have the same return type of the original one. When possible a version returning anOptionalis provided. For functional interface without return value, this method will be identical toignore().For functional interface with Object result, the principle is :
(xxx) -> { try { return Optional.ofNullable(realaction(xxx)); } catch (Exception e) { return Optional.empty(); } }For functional interface with primitive result, the principle is :(xxx) -> { try { return realaction(xxx); } catch (Exception e) { return defaultValue; } }For functional interface without result, the principle is :(xxx) -> { try { realaction(xxx); } catch (Exception e) { // do nothing } }
-
ignore
F ignore()
Converts this functional interface to the corresponding java standard functional interface returning a default value in case of error. For function interface without return value, error will be silently ignored.For functional interface with Object result, the principle is :
(xxx) -> { try { return realaction(xxx); } catch (Exception e) { return null; } }For functional interface with primitive result, the principle is :(xxx) -> { try { return realaction(xxx); } catch (Exception e) { return defaultValue; } }For functional interface without result, the principle is :(xxx) -> { try { realaction(xxx); } catch (Exception e) { // do nothing } }
-
documented
default Z documented(Supplier<String> toString)
Add atoStringmethod to the existing interface based on the receivedSupplier.- Parameters:
toString- the supplier to be used- Returns:
- a new interface, with
toStringusing the received supplier. - Throws:
NullPointerException- if toString is null- Since:
- 3.0.0
-
-