
com.almondtools.conmatch.exceptions.Exceptions Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of conmatch Show documentation
Show all versions of conmatch Show documentation
Hamcrest Matchers for generic programming idioms.
The newest version!
package com.almondtools.conmatch.exceptions;
public final class Exceptions {
private Exceptions() {
}
public static Throwable catchException(WithResult> code) {
return catchException(code, Throwable.class);
}
public static T catchException(WithResult> code, Class clazz) {
try {
code.run();
return null;
} catch (Throwable exception) {
if (clazz.isInstance(exception)) {
return clazz.cast(exception);
} else {
return null;
}
}
}
public static Throwable catchException(WithoutResult code) {
return catchException(code, Throwable.class);
}
public static T catchException(WithoutResult code, Class clazz) {
try {
code.run();
return null;
} catch (Throwable exception) {
if (clazz.isInstance(exception)) {
return clazz.cast(exception);
} else {
return null;
}
}
}
public interface WithResult {
T run() throws Throwable;
}
public interface WithoutResult {
void run() throws Throwable;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy