com.cloud.lego.exception.spring.boot.BusinessException Maven / Gradle / Ivy
package com.cloud.lego.exception.spring.boot;
import com.cloud.lego.model.spring.boot.BeanMap;
import com.cloud.lego.model.spring.boot.BusinessResult;
import com.cloud.lego.util.spring.boot.Tools;
import lombok.Getter;
import lombok.Setter;
import java.io.Serializable;
/**
* 业务处理异常类,定义常见业务异常
*
*
* 例如:
* throw new BusinessException(601,"系统异常");
*
*
* @author Andy
*/
@Setter
@Getter
public class BusinessException extends RuntimeException {
/**
* 错误码
*/
protected Serializable code;
/**
* 扩展信息
*/
protected BeanMap ext = BeanMap.of();
public BusinessException(Serializable code, String message) {
super(message);
this.code = code;
}
public BusinessException(Serializable code, String message, BeanMap ext) {
super(message);
this.code = code;
this.ext = ext;
}
public BusinessException(BusinessResult result) {
super(result.getMessage());
this.code = result.getCode();
this.ext = result.getExt();
}
/**
* 根据返回结果对参数进行格式化
*
* @param result 参数定义包含占位符{} message示例 上传文件类型{}异常
* @param params 格式化参数
*/
public BusinessException(BusinessResult result, Object... params) {
super(Tools.format(result.getMessage(), params));
this.code = result.getCode();
this.ext = result.getExt();
}
/**
* 不会收集线程的整个异常栈信息,提升性能10倍左右
*/
@Override
public Throwable fillInStackTrace() {
return this;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy