编程语言
首页 > 编程语言> > Java中throws与throw的区别

Java中throws与throw的区别

作者:互联网

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);
    }
}

 

标签:throw,Java,throws,Judge,message,异常,public
来源: https://blog.csdn.net/qq_58510930/article/details/123140912