2022-04-02 22:01:29 +02:00
|
|
|
package io.gitlab.jfronny.libjf.generic;
|
2022-03-31 20:45:10 +02:00
|
|
|
|
|
|
|
import java.util.function.Consumer;
|
|
|
|
import java.util.function.Function;
|
|
|
|
|
|
|
|
public class Try {
|
|
|
|
public static void orElse(ThrowingRunnable<?> tr, Consumer<Throwable> alternative) {
|
|
|
|
try {
|
|
|
|
tr.run();
|
|
|
|
} catch (Throwable e) {
|
|
|
|
alternative.accept(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static <T> T orElse(ThrowingSupplier<T, ?> tr, Function<Throwable, T> alternative) {
|
|
|
|
try {
|
|
|
|
return tr.get();
|
|
|
|
} catch (Throwable e) {
|
|
|
|
return alternative.apply(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|