异常学习时的一种顶层范式的思想
一种顶层范式的思想,作为小白,以后编程作为借鉴
定义一个抽象类,作为自动化框架的顶层异常
import com.google.common.base.Joiner;
//为自动化框架设计的顶层异常
public abstract class AutoRuntimeException extends RuntimeException {
public AutoRuntimeException() {
}
public AutoRuntimeException(String... args) {
super(Joiner.on("-").join(args));
}
public AutoRuntimeException(String message, Throwable cause) {
super(message, cause);
}
public AutoRuntimeException(Throwable cause) {
super(cause);
}
public AutoRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}
对于不同应用都可以继承自顶层异常,作为细节异常
//继承自顶层异常的细节异常
public class HttpAutoException extends AutoRuntimeException {
public HttpAutoException() {
}
public HttpAutoException(String... args) {
super(args);
}
public HttpAutoException(String message, Throwable cause) {
super(message, cause);
}
public HttpAutoException(Throwable cause) {
super(cause);
}
public HttpAutoException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}
//继承自顶层异常的细节异常
public class MySQLAutoException extends AutoRuntimeException {
public MySQLAutoException() {
}
public MySQLAutoException(String... args) {
super(args);
}
public MySQLAutoException(String message, Throwable cause) {
super(message, cause);
}
public MySQLAutoException(Throwable cause) {
super(cause);
}
public MySQLAutoException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
}
}
优点,就是对于异常,你约定了一个模板,以后再调用和抛出时,知道细节,同时也知道怎么定义
浙公网安备 33010602011771号