All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.simplaex.bedrock.ThrowingRunnable Maven / Gradle / Ivy

There is a newer version: 2020.02.27
Show newest version
package com.simplaex.bedrock;

import java.util.function.Consumer;

@FunctionalInterface
public interface ThrowingRunnable extends Runnable {

  void execute() throws Exception;

  @Override
  default void run() {
    try {
      execute();
    } catch (final Error | RuntimeException exc) {
      throw exc;
    } catch (final Exception exc) {
      throw new RuntimeException(exc);
    }
  }

  default Runnable safe(final Consumer errorHandler) {
    return () -> {
      try {
        execute();
      } catch (final Exception exc) {
        errorHandler.accept(exc);
      }
    };
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy