Java 中的 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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP