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
热门推荐
6 保研的祝福语简短
10 年轻20岁祝福语简短
11 朋友结婚祝福语信息简短
12 女孩婚礼贺卡祝福语简短
13 30段点歌简短祝福语
14 虎年春节祝福语图文简短
15 写给后妈祝福语大全简短
16 简短回复生日祝福语
17 校长送毕业祝福语简短
18 毕业立体贺卡祝福语简短