import java.util.Arrays;
public class _3_01_2Demo {
private int age;
public static void main(String[] args) {
// 1.异常
// RnntimeException 运行时报错 需要我们认为改变 编译器能通过
// String s = null;
// System.out.println(s.length()); //空指针
// 所有不是RuntimeException checked Exception 已检查异常 编译器不能通过
// 两种方式:try catch or throws Exception
// 2.自定义异常
// _3_01_2Demo ts = new _3_01_2Demo();
// ts.setAge(-2);
}
public void setAge(int n){
if(n<0){
throw new IllegalAgeException("年龄不能为负数");
}
this.age = n;
}
}
class IllegalAgeException extends RuntimeException{
public IllegalAgeException(){
}
public IllegalAgeException(String msg){
super(msg);
}
}