com.loocme.sys.exception.LoocScriptException Maven / Gradle / Ivy
package com.loocme.sys.exception;
import java.util.Locale;
import java.util.ResourceBundle;
import com.loocme.sys.util.StringUtil;
/**
* loocme 脚本运行的异常信息
*
* @author loocme
*
*/
public class LoocScriptException extends Exception
{
private static final long serialVersionUID = 1L;
private String code;
private String desc;
/**
* 通过code获取响应的描述,若描述中存在%s需要替换的内容,则args会根据元素的位置进行替换
*
* @param code
* 响应码
* @param args
* 替换的参数
*/
public LoocScriptException(String code, Object... args)
{
super();
this.code = code;
String desc = "";
Locale locale = Locale.getDefault();
ResourceBundle resource = ResourceBundle.getBundle(this.getClass().getPackage().getName().replaceAll("\\.", "/") + "/i18n/LScriptException", locale);
if (resource.containsKey(this.code))
{
desc = resource.getString(this.code);
}
desc = StringUtil.isNull(desc) ? "%s" : "";
this.desc = String.format(desc, args);
}
/**
* 异常code默认为99, 异常信息为cause.getMessage获取到的其他异常信息
*
* @param cause
*/
public LoocScriptException(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