throws : 一般用在类库端
throws : 抛异常,一般用于类库端,并不能解决问题,依然会终止程序生命周期执行
throws 异常,这种方式并不会处理异常,只是一种提醒机制,告诉调用人员,这里肯能有问题
如果上家提醒了你,要么你就使用try…catch…解决,要么你就提醒下家
public class Exception_03 {
public static void main(String[] args) throws FileNotFoundException {
m1();
System.out.println("-----------");
}
public static void m1() throws FileNotFoundException{
m2();
}
public static void m2() throws FileNotFoundException{
m3();
}
public static void m3() throws FileNotFoundException{
new FileInputStream("23");
}
}
throws 可以抛出多个异常,用 逗号 隔开
并且throws的时候,不需要考虑继承关系和先后顺序,因为只是个提醒
throw : 异常源点,起点
public class Exception_06 {
public static void main(String[] args) throws Exception,FileNotFoundException,IOException{
new FileInputStream("");
}
}