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

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

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

import java.util.function.Consumer;

/**
 * Version of the {@link Consumer} able to throw Checked {@link Exception Exceptions}.
 */
@FunctionalInterface
public interface ThrowingConsumer {

    void accept(T t) throws Exception;

    /**
     * @param throwing the {@link ThrowingConsumer} to convert to {@link Consumer}
     * @param errorHandler used when an {@link Exception} is raised by the given {@link ThrowingConsumer}
     */
    static  Consumer silent(ThrowingConsumer throwing, Consumer errorHandler) {
        return t -> {
            try {
                throwing.accept(t);
            } catch (Exception e) {
                errorHandler.accept(e);
            }
        };
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy