com.softicar.platform.common.core.throwable.ThrowableCauseTester Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of platform-common Show documentation
Show all versions of platform-common Show documentation
The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.
package com.softicar.platform.common.core.throwable;
import java.util.function.Predicate;
/**
* Checks if a {@link Throwable} is caused by given {@link Throwable} class.
*
* @author Oliver Richers
*/
public class ThrowableCauseTester implements Predicate {
private final Class throwableClass;
public ThrowableCauseTester(Class throwableClass) {
this.throwableClass = throwableClass;
}
@Override
public boolean test(Throwable throwable) {
if (throwableClass.isInstance(throwable)) {
return true;
} else {
Throwable cause = throwable.getCause();
if (cause != null) {
return test(cause);
} else {
return false;
}
}
}
}