案例研究之聊聊 QLExpress 源码 (四)
异常模块通常是每个源码框架都会自己根据自己框架的不同异常进行自定义化的封装,方便能够快速定位本身系统的问题。
四、异常模块(Exception)
4.1、QLBizException业务异常
非QLExpress框架捕获的业务系统代码的异常
package com.ql.util.express.exception;
/**
* 非QLExpress框架捕获的业务系统代码的异常
* @author tianqiao@taobao.com
* @since 2019/6/18 2:13 PM
*/
public class QLBizException extends Exception {
public QLBizException() {
}
public QLBizException(String message) {
super(message);
}
public QLBizException(String message, Throwable cause) {
super(message, cause);
}
}
4.2、QLCompileException编译异常
编译器的异常信息
package com.ql.util.express.exception;
/**
* 编译器的异常信息
* @author tianqiao@taobao.com
* @since 2019/6/18 2:13 PM
*/
public class QLCompileException extends Exception {
public QLCompileException() {
}
public QLCompileException(String message) {
super(message);
}
public QLCompileException(String message, Throwable cause) {
super(message, cause);
}
}
4.3、QLException运行异常
QLExpress的框架执行过程中捕获的异常
package com.ql.util.express.exception;
/**
* QLExpress的框架执行过程中捕获的异常
* @author tianqiao@taobao.com
* @since 2019/6/18 2:13 PM
*/
public class QLException extends Exception {
public QLException() {
}
public QLException(String message) {
super(message);
}
public QLException(String message, Throwable cause) {
super(message, cause);
}
}
4.4、QLSecurityRiskException系统安全相关异常
系统安全相关异常(比如调用操作系统命令等)
package com.ql.util.express.exception;
/**
* 系统安全相关异常(比如调用操作系统命令等)
* @author tianqiao@taobao.com
* @since 2019/6/18 10:36 AM
*/
public class QLSecurityRiskException extends QLException {
public QLSecurityRiskException() {
}
public QLSecurityRiskException(String message) {
super(message);
}
}
4.5、QLTimeOutException超时异常
设置了timeoutMills造成的超时异常
package com.ql.util.express.exception;
/**
* 设置了timeoutMills造成的超时异常
* @author tianqiao@taobao.com
* @since 2019/6/18 10:36 AM
*/
public class QLTimeOutException extends QLException {
public QLTimeOutException() {
}
public QLTimeOutException(String message) {
super(message);
}
}
4.6、小结
本节主要描述了异常的定义,这里开源框架的借鉴思想:
业务异常、运行异常、编译异常、安全异常、超时异常的分类
明细的异常能够更快的,更方便定位问题