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

pl.touk.throwing.Checker Maven / Gradle / Ivy

There is a newer version: 1.6.1
Show newest version
package pl.touk.throwing;

import pl.touk.throwing.exception.WrappedException;

import java.util.function.Supplier;

public final class Checker {
    private Checker() {
    }

    @SuppressWarnings("unchecked")
    public static  T checked(Class exceptionType, Supplier supplier) throws E {
        try {
            return supplier.get();
        } catch (WrappedException ex) {
            if (exceptionType.isInstance(ex.getCause())) {
                throw (E) ex.getCause();
            } else {
                throw ex;
            }
        }
    }

    @SuppressWarnings("unchecked")
    public static  T checked(Supplier supplier) throws Throwable {
        try {
            return supplier.get();
        } catch (WrappedException ex) {
            throw ex.getCause();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy