/**
 * 
 */
package com.github.phantomthief.util;

import static java.util.Optional.ofNullable;
import static org.slf4j.LoggerFactory.getLogger;

import java.util.Optional;
import java.util.concurrent.Callable;

import org.slf4j.Logger;

import com.google.common.base.Throwables;

/**
 * @author w.vela
 */
public final class MoreFunctions {

    private static final Logger logger = getLogger(MoreFunctions.class);

    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));
    }

    public static <R> R throwing(Callable<R> callable) {
        return catching(callable, Throwables::propagate);
    }

    public static <R, X extends Throwable> R catching(Callable<R> callable,
            ThrowableConsumer<Throwable, X> exceptionHandler) throws X {
        try {
            return callable.call();
        } catch (Throwable e) {
            exceptionHandler.accept(e);
            return null;
        }
    }

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

    public static <T, R> R throwing(ThrowableFunction<T, R, Exception> function, T t) {
        return catching(function, t, Throwables::propagate);
    }

    public static <T, R, X extends Throwable> R catching(
            ThrowableFunction<T, R, Exception> function, T t,
            ThrowableConsumer<Throwable, X> exceptionHandler) throws X {
        try {
            return function.apply(t);
        } catch (Throwable e) {
            exceptionHandler.accept(e);
            return null;
        }
    }
}

@@ -687,78 +687,495 @@
 ic %3C
-R%3E R throwing(Callable%3CR%3E callable) %7B%0A        return catching(callable
+X extends Exception%3E void catching(ThrowableRunnable%3CX%3E callable) %7B%0A        catching(() -%3E %7B%0A            callable.run();%0A            return null;%0A        %7D, e -%3E logger.error(%22%22, e));%0A    %7D%0A%0A    public static %3CR%3E R throwing(Callable%3CR%3E callable) %7B%0A        return catching(callable, Throwables::propagate);%0A    %7D%0A%0A    public static %3CX extends Exception%3E void throwing(ThrowableRunnable%3CX%3E callable) %7B%0A        catching(() -%3E %7B%0A            callable.run();%0A            return null;%0A        %7D
 , Th

add new catching and throwing overrides for runnable (#6)