慕用0597549
慕哥0127756
衣袂倚斜阳
BusinessException extends Exception 为受检查的异常(checked exceptions),其必须被 try{}catch语句块所捕获,或者在方法签名里通过throws子句声明
慕大大神
8分30秒
挨踢人
this 是 谁调用返回的就是谁
慕瓜5137767
假面先生丶hha
MySweeties
对于通用类型错误码,比如视频中的类型错误,可能在实际需求中有多个不同的反馈信息,比如邮箱错误,用户名错误等,但是它们都对应于同一错误码。这样写可以不必注意错误码而只注意错误信息,返回this会带着错误码。
webcat
反编译枚举类就知道,枚举类的成员变量都是用static final来修饰的,这样修改绝对存在线程安全问题,建议msg不要在这里修改
忠厚老实的阿宇
千江有水千江月万里无云万里云1
已经出了
慕慕4275092
做统一异常处理,接口是定义一些统一错误信息的方法,然后枚举实现接口,可以实现接口的方法,以及自定义枚举异常信息,然后构造自定义错误Msg和Code方法,最后通过另一个BusinessException类继承该类,实现方法并且扩展方法 用于后面的内容使用
weibo_圣托里尼的春_0
weibo_圣托里尼的春_0
错误信息返回的类型当然选择通用返回类型CommonError
sunbohan00
不加其实也没有影响,子类的无参或者有参构造函数都会默认调用父类的无参构造函数,老师这里可能只是强调一下Exception中默认构造函数做的工作吧。
public class TestExtends {
public static void main(String[] args) {
new Child();
System.out.println("-----------");
new Child(1,"1");
}
}
class Parent {
protected Integer id;
protected String name;
public Parent() {
System.out.println("parent no arg constructor");
}
public Parent(Integer id, String name) {
this.id = id;
this.name = name;
System.out.println("parent all args constructor");
}
}
class Child extends Parent{
public Child() {
System.out.println("child no arg constructor");
}
public Child(Integer id, String name) {
this.id = id;
this.name = name;
System.out.println("child all args constructor");
}
}打印
parent no arg constructor
child no arg constructor
-----------
parent no arg constructor
child all args constructor