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

org.valkyriercp.application.exceptionhandling.SimpleExceptionHandlerDelegate Maven / Gradle / Ivy

There is a newer version: 1.3
Show newest version
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 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 throwableClass) {
        setThrowableClassList(Lists.>newArrayList(throwableClass));
    }

    public SELF forThrowable(Class 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