<commit_before>package org.guppy4j;

import java.util.function.Function;

/**
 * Wraps checked exceptions
 */
public final class Exceptions {

    public interface DoSomething<E extends Exception> {
        void doIt() throws E;
    }

    public static <RE extends RuntimeException, E extends Exception> void tryCatchWrap(
            DoSomething<E> something,
            Class<E> exClass,
            Function<Exception, RE> exWrapper)
            throws RE {
        try {
            something.doIt();
        } catch (RuntimeException re) {
            throw re;
        } catch (Exception e) {
            if (exClass.isInstance(e)) {
                throw exWrapper.apply(e);
            } else {
                // cannot happen
                throw new RuntimeException("Unexpected checked exception", e);
            }
        }
    }
}
<commit_msg>More generic exception wrapping<commit_after>package org.guppy4j;

import java.util.function.Function;

/**
 * Wraps checked exceptions
 */
public final class Exceptions {

    public interface DoSomething<E extends Exception> {
        void doIt() throws E;
    }

    public interface ReturnSomething<P, R, E extends Exception> {
        R doIt(P parameter) throws E;
    }

    public static <P, R, RE extends RuntimeException, E extends Exception>
    R tryCatchWrap(
            ReturnSomething<P, R, E> something,
            P parameter,
            Class<E> exClass,
            Function<Exception, RE> exWrapper) {
        try {
            return something.doIt(parameter);
        } catch (RuntimeException re) {
            throw re;
        } catch (Exception e) {
            if (exClass.isInstance(e)) {
                throw exWrapper.apply(e);
            } else {
                // cannot happen
                throw new RuntimeException("Unexpected checked exception", e);
            }
        }
    }

    public static <RE extends RuntimeException, E extends Exception>
    void tryCatchWrap(DoSomething<E> something,
                      Class<E> exClass, Function<Exception, RE> exWrapper)
            throws RE {
        tryCatchWrap(parameter -> {
                    something.doIt();
                    return null;
                },
                null, exClass, exWrapper);
    }
}

{'fraction_non_alphanumeric': 0.08644142167617376, 'fraction_numerical': 0.0008775778850372971, 'mean_word_length': 1.7636363636363637, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6808865', 'n_tokens_mistral': 593, 'n_tokens_neox': 574, 'n_words': 171}