Interface ThrowingRunnable<X extends Throwable>

Type Parameters:
X - the type of the exception thrown by the function
All Superinterfaces:
Runnable
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 ThrowingRunnable<X extends Throwable> extends Runnable
An extension of Runnable allowing throwing calls in its body.
  • Method Summary

    Modifier and Type
    Method
    Description
    static <@Any X extends Throwable>
    @NotNull ThrowingRunnable<X>
    Creates an empty (no-op) throwing runnable.
    default void
    run()
     
    void
    Runs an action.
    static <@Any X extends Throwable>
    @NotNull ThrowingRunnable<X>
    throwing(@NonNull Supplier<? extends @NotNull X> exceptionFactory)
    Creates a throwing runnable which always throws an exception produced by using the factory.
  • Method Details

    • runChecked

      void runChecked() throws X
      Runs an action.
      Throws:
      X - if an exception happens
    • run

      default void run()
      Specified by:
      run in interface Runnable
    • empty

      @NotNull static <@Any X extends Throwable> @NotNull ThrowingRunnable<X> empty()
      Creates an empty (no-op) throwing runnable.
      Type Parameters:
      X - any formal type of the (never thrown) exception
      Returns:
      empty throwing runnable
    • throwing

      @NotNull static <@Any X extends Throwable> @NotNull ThrowingRunnable<X> throwing(@NonNull @NonNull Supplier<? extends @NotNull X> exceptionFactory)
      Creates a throwing runnable which always throws an exception produced by using the factory.
      Type Parameters:
      X - the type of the exception thrown by the function
      Parameters:
      exceptionFactory - factory used for creation of the exception
      Returns:
      throwing runnable which always throws X by creating it via the provided factory
      Throws:
      NullPointerException - if exceptionFactory is null
      API note
      if the exceptionFactory produces null then NullPointerException will be thrown when attempting to throw the expected exception