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

com.loocme.sys.exception.ThirdJarException Maven / Gradle / Ivy

package com.loocme.sys.exception;

import java.util.Locale;
import java.util.ResourceBundle;

import com.loocme.sys.util.StringUtil;

/**
 * 第三方jar包定义的异常信息
 * 
 * @author loocme
 *
 */
public class ThirdJarException extends Exception
{

    private static final long serialVersionUID = 1L;

    private String code;
    private String desc;

    /**
     * 通过code获取响应的描述,若描述中存在%s需要替换的内容,则args会根据元素的位置进行替换
     * 
     * @param code
     *            响应码
     * @param args
     *            替换的参数
     */
    public ThirdJarException(String code, Object... args)
    {
        super();
        this.code = code;
        String desc = "";
        Locale locale = Locale.getDefault();
        ResourceBundle resource = ResourceBundle.getBundle(this.getClass().getPackage().getName().replaceAll("\\.", "/") + "/i18n/ThirdJarException", locale);
        if (resource.containsKey(this.code))
        {
            desc = resource.getString(this.code);
        }
        this.desc = StringUtil.isNull(desc) ? "%s" : String.format(desc, args);
    }

    /**
     * 异常code默认为99, 异常信息为cause.getMessage获取到的其他异常信息
     * 
     * @param cause
     */
    public ThirdJarException(Throwable cause)
    {
        super(cause);
        this.code = "99";
        this.desc = cause.getMessage();
    }

    /**
     * @return the status
     */
    public String getCode()
    {
        return this.code;
    }

    /**
     * @see java.lang.Throwable#getMessage()
     */
    @Override
    public String getMessage()
    {
        return this.desc;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy