Kev*_*ler 1 java exception-handling exception
public static void main(String[] args) {
File file = new File("foobar");
file.createNewFile();
String baz = "baz";
int myInt = Integer.parseInt(baz);
}
Run Code Online (Sandbox Code Playgroud)
在这段代码中,IDE或编译器会抱怨createNewFile()抛出了一个未处理的异常,我们需要捕获它以允许代码编译.
但是,parseInt()也抛出一个异常,NumberFormatException,但我们不需要捕获它,虽然它似乎是个好主意.为什么我们不需要捕获该异常?
| 归档时间: |
|
| 查看次数: |
110 次 |
| 最近记录: |