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

nl.hsac.fitnesse.fixture.util.ThrowingFunction Maven / Gradle / Ivy

There is a newer version: 5.3.17
Show newest version
package nl.hsac.fitnesse.fixture.util;

import java.util.function.Function;

/**
 * Functional interface to allow exceptions thrown by lambdas to be handled, or wrapped to runtime ones.
 */
@FunctionalInterface
public interface ThrowingFunction {
    R apply(T t) throws E;

    /**
     * Applies using t, wrapping converting any checked exception to a runtime one using exceptionWrapper
     * @param t parameter to supply to {@link #apply(Object)}.
     * @param exceptionWrapper function to convert checked exception to runtime one.
     * @param  type of runtime exception which will be thrown
     * @return result of apply(t)
     */
    default  R applyWrapped(T t, Function exceptionWrapper) {
        try {
            return apply(t);
        } catch (RuntimeException e) {
            throw e;
        } catch (Exception e) {
            throw exceptionWrapper.apply((E) e);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy