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

com.chutneytesting.tools.ThrowingConsumer Maven / Gradle / Ivy

There is a newer version: 3.0.0
Show newest version
package com.chutneytesting.tools;

import java.util.function.Consumer;

@FunctionalInterface
public interface ThrowingConsumer {
    void accept(T var1) throws Exception;

    /**
     * @throws UncheckedException if given {@link ThrowingFunction} throws
     */
    static  Consumer toUnchecked(ThrowingConsumer throwingConsumer) throws UncheckedException {
        return silence(throwingConsumer, e -> {
            throw UncheckedException.throwUncheckedException(e);
        });
    }

    static  Consumer silence(ThrowingConsumer throwingConsumer, Consumer exceptionHandler) {
        return t -> {
            try {
                throwingConsumer.accept(t);
            } catch (Exception e) {
                exceptionHandler.accept(e);
            }
        };
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy