为什么算术异常在java中是未检查异常
为什么算术异常是未检查异常,为什么我们在Java中定义两种类型的未检查异常和已检查异常 已检查异常是在编译时检查的异常。如果方法中的某些代码抛出选中的异常,则该方法必须处理该异常,或者必须使用throws关键字指定该异常为什么算术异常在java中是未检查异常,java,arithmeticexception,Java,Arithmeticexception,为什么算术异常是未检查异常,为什么我们在Java中定义两种类型的未检查异常和已检查异常 已检查异常是在编译时检查的异常。如果方法中的某些代码抛出选中的异常,则该方法必须处理该异常,或者必须使用throws关键字指定该异常 import java.io.*; class Main { public static void main(String[] args) { FileReader file = new FileReader("C:\\test\\a.txt");
import java.io.*;
class Main {
public static void main(String[] args) {
FileReader file = new FileReader("C:\\test\\a.txt");
BufferedReader fileInput = new BufferedReader(file);
// Print first 3 lines of file "C:\test\a.txt"
for (int counter = 0; counter < 3; counter++)
System.out.println(fileInput.readLine());
fileInput.close();
}
}
+-----------+
| Throwable |
+-----------+
/ \
/ \
+-------+ +-----------+
| Error | | Exception |
+-------+ +-----------+
/ | \ / | \
\_________/ \____/ \
+------------------+
unchecked checked | RuntimeException |
+------------------+
/ | | | \
\_________________/
unchecked