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

com.github.nicosensei.textbatch.ToolException Maven / Gradle / Ivy

/**
 *
 */
package com.github.nicosensei.textbatch;

import org.apache.log4j.Level;

import com.github.nicosensei.commons.exceptions.Handleable;


/**
 * Base class for all exception generated by the tool.
 *
 * @author ngiraud
 *
 */
public abstract class ToolException extends Handleable {

    private static final long serialVersionUID = 8116761541462247081L;

    private final boolean verbose;

    /**
     *
     * @param code
     * @param messageFormat
     * @param params
     * @param criticity
     * @param verbose
     */
    protected ToolException(
            String code,
            String messageFormat,
            String[] params,
            Level criticity,
            boolean verbose) {
        super(code, messageFormat, params, criticity);
        this.verbose = verbose;
        log();
    }

    /**
     *
     * @param code
     * @param messageFormat
     * @param params
     * @param criticity
     * @param cause
     * @param verbose
     */
    protected ToolException(
            String code,
            String messageFormat,
            String[] params,
            Level criticity,
            Throwable cause,
            boolean verbose) {
        super(code, messageFormat, params, criticity, cause);
        this.verbose = verbose;
        log();
    }

    protected ToolException(
            String code,
            String messageFormat,
            String[] params,
            Level criticity) {
        this(code, messageFormat, params, criticity, true);
        log();
    }

    protected ToolException(
            String code,
            String messageFormat,
            String[] params,
            Level criticity,
            Throwable cause) {
        this(code, messageFormat, params, criticity, cause, true);
        log();
    }

    public Throwable getRootCause() {
        Throwable rootCause = this;
        Throwable cause = getCause();
        while (cause != null) {
            rootCause = cause;
            cause = cause.getCause();
        }
        return rootCause;
    }

    public final boolean isVerbose() {
        return verbose;
    }

    protected void log() {
        Tool.getInstance().logError(this);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy