Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/main/java/com/github/phantomthief/util/MoreFunctions.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,21 @@
public final class MoreFunctions {

private static final Logger logger = getLogger(MoreFunctions.class);
private static final String FAIL_SAFE_MARK = "[fail safe]";

public static <R> Optional<R> catchingOptional(Callable<R> callable) {
return ofNullable(catching(callable));
}

public static <R> R catching(Callable<R> callable) {
return catching(callable, e -> logger.error("", e));
return catching(callable, e -> logger.error(FAIL_SAFE_MARK, e));
}

public static <X extends Exception> void runCatching(ThrowableRunnable<X> callable) {
catching(() -> {
callable.run();
return null;
}, e -> logger.error("", e));
}, e -> logger.error(FAIL_SAFE_MARK, e));
}

public static <R> R throwing(Callable<R> callable) {
Expand Down Expand Up @@ -73,7 +74,7 @@ public static <R, X extends Throwable> R catching(Callable<R> callable,
}

public static <T, R> R catching(ThrowableFunction<T, R, Exception> function, T t) {
return catching(function, t, e -> logger.error("", e));
return catching(function, t, e -> logger.error(FAIL_SAFE_MARK, e));
}

public static <T, R> R throwing(ThrowableFunction<T, R, Exception> function, T t) {
Expand Down