目录
文件找不到异常(FileNotFoundException)
类找不到异常(ClassNotFoundException)
没有这个方法异常(NoSuchMethodException)
索引越界异常(IndexOutOfBoundsException)
索引越界异常(IndexOutOfBoundsException)
方法不存在异常(NoSuchMethodException)
字符串索引越界异常(StringIndexOutOfBoundsException)
内存溢出异常(OutOfMemoryError)
不是程序能控制的,分配的对象的内存超出了当前最大的堆内存,需要调整堆内存大小(-Xmx)以及优化程序。
IO异常(IOException)
受检查异常,需要进行捕获。捕获那些知道如何处理的异常,将不知道如何处理的异常继续传递下去,直接抛出,在方法签名处使用throws关键字声明抛出的异常。
private static void readFile(String filePath) throws IOException {
File file = new File(filePath);
String result;
BufferedReader reader = new BufferedReader(new FileReader(file));
while((result = reader.readLine())!=null) {
System.out.println(result);
}
reader.close();
}
文件找不到异常(FileNotFoundException)
如果文件不存在就会抛出这种异常。
private static