org.valkyriercp.application.exceptionhandling.SimpleExceptionHandlerDelegate Maven / Gradle / Ivy
package org.valkyriercp.application.exceptionhandling;
import com.google.common.collect.Lists;
import java.util.List;
/**
* Handles the thrownTrowable by the exception handler if it is an instance of one of the throwableClassList.
* Note: Also subclasses of the classes in the throwableClassList will be handled by the exception handler.
*
* @author Geoffrey De Smet
* @since 0.3.0
*/
public class SimpleExceptionHandlerDelegate> extends AbstractExceptionHandlerDelegate {
private List> throwableClassList;
public SimpleExceptionHandlerDelegate() {
}
public SimpleExceptionHandlerDelegate(Class extends Throwable> throwableClass,
Thread.UncaughtExceptionHandler exceptionHandler) {
this(Lists.>newArrayList(throwableClass), exceptionHandler);
}
public SimpleExceptionHandlerDelegate(List> throwableClassList,
Thread.UncaughtExceptionHandler exceptionHandler) {
super(exceptionHandler);
this.throwableClassList = throwableClassList;
}
public void setThrowableClass(Class extends Throwable> throwableClass) {
setThrowableClassList(Lists.>newArrayList(throwableClass));
}
public SELF forThrowable(Class extends Throwable> throwableClass) {
setThrowableClass(throwableClass);
return self();
}
public void setThrowableClassList(List> throwableClassList) {
this.throwableClassList = throwableClassList;
}
public SELF forThrowables(List> throwableClassList) {
setThrowableClassList(throwableClassList);
return self();
}
public boolean hasAppropriateHandlerPurged(Throwable throwable) {
for (Class throwableClass : throwableClassList) {
if (throwableClass.isInstance(throwable)) {
return true;
}
}
return false;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy