import java.io.FileNotFoundException;
public class TryCatchDemo {
public static void main(String[] args) {
try {
read("b.txt");
} catch (FileNotFoundException e) {
System.out.println(e);
}
System.out.println("文件存在");
}
public static void read(String path) throws FileNotFoundException {
if (!path.equals("a.txt")) {
throw new FileNotFoundException("文件不存在");
}
}
}
catch下不加return; 抓到异常后还是会执行System.out.println(“文件存在”);
加了之后不会执行System.out.println(“文件存在”);
也可以把