Java中的catch块是什么?
catch语句涉及声明您要捕获的异常类型。如果try块中发生异常,则检查try之后的catch块。如果在catch块中列出了发生的异常类型,则将异常传递到catch块的方式与将参数传递给方法参数的方式一样。
示例
import java.io.File;
import java.io.FileInputStream;
public class Test {
public static void main(String args[]) {
System.out.println("Hello");
try {
File file = new File("my_file");
FileInputStream fis = new FileInputStream(file);
} catch(Exception e) {
System.out.println("Given file path is not found");
}
}
}输出结果
Hello Given file path is not found
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短