Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/347.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么算术异常在java中是未检查异常_Java_Arithmeticexception - Fatal编程技术网

为什么算术异常在java中是未检查异常

为什么算术异常在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");

为什么算术异常是未检查异常,为什么我们在Java中定义两种类型的未检查异常和已检查异常

已检查异常是在编译时检查的异常。如果方法中的某些代码抛出选中的异常,则该方法必须处理该异常,或者必须使用throws关键字指定该异常

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