com.simplaex.bedrock.ThrowingRunnable Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bedrock Show documentation
Show all versions of bedrock Show documentation
Essential utilities for modern Java.
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 super Exception> errorHandler) {
return () -> {
try {
execute();
} catch (final Exception exc) {
errorHandler.accept(exc);
}
};
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy