pl.touk.throwing.Checker Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of throwing-function Show documentation
Show all versions of throwing-function Show documentation
Java 8+ functional interfaces with checked exceptions support
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();
}
}
}