我创建了扩展Exception类的自定义基本异常.后来我正在扩展MyBaseException又把另一个类 - 这次是specyfic异常类.而我现在对SonarQube之一有一个问题 - 特别是" 类似命名的类"Exception"应该扩展"Exception"或子类 "规则.类声明看起来像这样:
import org.apache.log4j.Logger;
import org.springframework.http.HttpStatus;
public class MyBaseException extends Exception {
public MyBaseException(int code, String message) {
super(message);
this.code = code;
LOGGER.error("Exception with HttpStatus code: " + code + " Msg: "
+ message);
}
public MyBaseException(HttpStatus code, String message) {
this(code.value(), message);
}
public int getCode() {
return code;
}
}
import org.springframework.http.HttpStatus;
public class SpecException extends MyBaseException {
public SpecException (HttpStatus code, String message) {
super(code, message);
} …Run Code Online (Sandbox Code Playgroud)