Interface ExceptionHandlerSupport<F,L,Z extends ExceptionHandlerSupport<F,L,Z>>

    • Method Detail

      • exceptionMapper

        default Function<Exception,RuntimeExceptionexceptionMapper()
        Mapping operation to convert the exception that may be thrown during execution to RuntimeException.

        The default mapper function may be changed by :

        • Using the second argument of the various unchecked methods. 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
      • uncheck

        F uncheck()
        Converts this functional interface to the corresponding one in java and wrap exception using exceptionMapper().

        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);
                }
         }
         
        Returns:
        the unchecked operation
        See Also:
        lift(), ignore()
      • 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 an Optional is provided. For functional interface without return value, this method will be identical to ignore().

        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
                }
         }
         
        Returns:
        the lifted function
        See Also:
        uncheck(), ignore()
      • 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
                }
         }
         
        Returns:
        the operation that ignore error
        See Also:
        uncheck(), lift()
      • documented

        default Z documented​(Supplier<String> toString)
        Add a toString method to the existing interface based on the received Supplier.
        Parameters:
        toString - the supplier to be used
        Returns:
        a new interface, with toString using the received supplier.
        Throws:
        NullPointerException - if toString is null
        Since:
        3.0.0