java 异常处理3
2020-12-13 06:09
标签:class cep pre 异常处理 年龄 except exception strong 编译 自定义异常: java 异常处理3 标签:class cep pre 异常处理 年龄 except exception strong 编译 原文地址:https://blog.51cto.com/14437184/2419087
throws,不处理异常,丢给调用者处理
public static void f() throws IOException{
...
}
丢给调用方法处理
public static void main(String[]args) throws IOException{
f();
}
main()方法丢给jre处理
在运行时定义的异常用throw,如果是编译器异常则需要throws或try-catch,比如继承的是ExceptionPerson p=new Person();
p.setAge(-1);
class Person{
private int age;
public void setAge(int age)
{
if(age