Interface ThrowableSupplier<T>

  • Functional Interface:
    This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

    @FunctionalInterface
    public interface ThrowableSupplier<T>
    • Method Detail

      • get

        T get()
        throws java.lang.Throwable
        Applies this function to the given argument.
        Returns:
        the supplied result
        Throws:
        java.lang.Throwable - if met with any error
      • execute

        default T execute​(java.util.function.Function<java.lang.Throwable,​T> exceptionHandler)
        Execute get() with the customized exception handling
        Parameters:
        exceptionHandler - the handler to handle any exception that the get() method throws
        Returns:
        the supplied result
        See Also:
        execute()
      • handleException

        default T handleException​(java.lang.Throwable failure)
        Handle any exception that the get() method throws
        Parameters:
        failure - the instance of Throwable
        Returns:
        the result after the exception handling
      • execute

        static <T> T execute​(ThrowableSupplier<T> supplier,
                             java.util.function.Function<java.lang.Throwable,​T> exceptionHandler)
                      throws java.lang.NullPointerException
        Executes ThrowableSupplier with the customized exception handling
        Type Parameters:
        T - the supplied type
        Parameters:
        supplier - ThrowableSupplier
        exceptionHandler - the handler to handle any exception that the get() method throws
        Returns:
        the result after execution
        Throws:
        java.lang.NullPointerException - if supplier or exceptionHandler is null