异常抛出类
来源:互联网 发布:程序员入门教程 编辑:程序博客网 时间:2024/06/04 17:49
package com.lz.ctsframework.core.support;import java.text.MessageFormat;/** * * <b>类说明:</b>Service层统一抛出的异常 * * <p> * <b>详细描述:</b> * * @author liuhuanchao * @since 2016-04-18 */public class ServiceException extends RuntimeException { private static final long serialVersionUID = 6514891174875747380L; /** 异常错误码 **/ private String code; /** 异常描述 **/ private String msg; /** 扩展异常描述(包括msg) **/ private String extMsg; /** * ServiceException构造方法,有format字符组 * @param errorCode 错误码 * @param param format字符组 * @param extMsg 扩展信息,给出具体的错误值信息等 */ public ServiceException(ErrorCode errorCode,String param[],String ... extMsg) { super(null==errorCode ? "" : errorCode.getCode()); init(errorCode, param,extMsg); } /** * ServiceException构造方法,有format字符组 * @param errCode * @param paramsList */ public ServiceException(ErrorCode errCode, Object... paramsList) { Object[] params = null; if ((paramsList != null) && (paramsList.length > 0) && ((paramsList[(paramsList.length - 1)] instanceof Throwable))) { Object[] newParam = new Object[paramsList.length - 1]; System.arraycopy(paramsList, 0, newParam, 0, newParam.length); params = newParam; super.initCause((Throwable)paramsList[(paramsList.length - 1)]); } else { params = paramsList; super.initCause(null); } this.code = null==errCode ? "" : errCode.getCode(); this.msg = null==errCode ? "" : MessageFormat.format(errCode.getMsg(),params); this.extMsg = this.msg; } private void init(ErrorCode errorCode, String param[], String... extMsg) { this.code = null==errorCode ? "" : errorCode.getCode(); this.msg = null==errorCode ? "" : MessageFormat.format(errorCode.getMsg(),param); StringBuilder builder = new StringBuilder(100); builder.append(this.msg); if(null != extMsg){ for(String ext : extMsg ){ builder.append("[").append(ext).append("]"); } } this.extMsg = builder.toString(); } /** * * @param code 错误码 * @param msg 描述信息 */ public ServiceException(String code, String msg) { super(code+":"+msg); this.code = code; this.msg = msg; } /** * 带Exception的构造方法,传format字符数组 * @param errorCode 错误码基类 * @param e 异常 * @param extMsg 扩展信息,给出具体的错误值信息等 */ public ServiceException(ErrorCode errorCode, Throwable e,String param[] , String ...extMsg ) { super(null==errorCode ? "" : errorCode.getCode(), e); init(errorCode, param, extMsg); } /** * * @param code 错误码 * @param msg 描述信息 * @param e 异常 */ /*public ServiceException(String code, String msg,Throwable e) {super(code+":"+msg, e);this.code = code;this.msg = msg; }*/ /** * * * 方法说明:异常错误码 * * @return */ public String getCode() { return code; } /** * * * 方法说明:异常描述信息 * * @return */ public String getMsg() { return msg; } public String getExtMsg() { return extMsg; } @Override public String getMessage() { return super.getMessage() + ","+extMsg; } public static void main(String[] args) { }}
0 0
- Java异常抛出类
- 异常抛出类
- 异常类抛出使用:fillInStackTrace
- OC抛出异常与自定义异常类
- 抛出异常
- 抛出异常
- 抛出异常
- 抛出异常
- 抛出异常
- 抛出异常
- 抛出异常
- 抛出异常
- 抛出异常
- 抛出异常
- 抛出异常
- Python 自定义异常类,主动捕获异常,主动抛出异常
- 通过抛出一个异常查找调用类
- 常用自定义异常抛出实现类
- gdb调试程序
- Python for Everybody-Using Python to Access Web DatExtracting Data With Regular Expressions
- Java定位CPU使用高问题
- Vim快捷键简介
- Linux环境下段错误的产生原因及调试方法小结
- 异常抛出类
- 欢迎使用CSDN-markdown编辑器
- iOS 代理传值
- Swifit指纹识别小Demo
- js中使用EL表达式
- 剑指offer之面试题9:斐波那契数列
- boost的配置解析库
- EEPROM-24LC512 family
- JSON处理类