throws | 异常处理的一种方式,用在方法声明处,后面是异常的类型 |
throw | 手动生成异常对象的关键字,在方法体中,后面是异常的对象 |
package Learn;
public class Test {
public static void main(String[] args) throws Judge {
int age=152;
if (age<=10||age>=120){
throw new Judge("年龄错误");
}
}
}
class Judge extends Exception{
public Judge(String message) {
super(message);
}
}