异常处理的分类
1 package com.fu.java5; 2 3 /** 4 * Error:java虚拟机无法解决的严重问题。如:JVM系统内部错误、资源耗尽等严重情况,比如StackOverflowError 5 * 一般不编写针对性的代码进行处理。 6 */ 7 public class ErrorTest { 8 public static void main(String[] args) { 9 //1.栈溢出:java.lang.StackOverflowError 10 // mian(args); 11 //2.堆溢出:java.lang.OutOfMemoryError(简称OOM) 12 Integer[] arr = new Integer[1024*1024*1024]; 13 } 14 }
1 package com.fu.java5; 2 3 import org.junit.jupiter.api.Test; 4 5 /** 6 * 一、异常的体系与结构 7 * java.lang.Throwable 8 * ----java.lang.Error:一般不编写针对性的代码进行处理 9 * ----java.lang.Exception:可以进行处理 10 * ----编译时异常(checked) 11 * ----IOException 12 * ----FileNotFoundException 13 * ----ClassNotFoundException 14 * ----运行时异常(unchecked) 15 * ----NullPointException 16 * ----ArrayIndexOutOfBoundException 17 * ----ClassCastException 18 * ----NumberFormatException 19 * ----ArithmeticException 20 * 21 * 22 */ 23 public class ExceptionTest { 24 //NullPointException 25 // @Test 26 // public void test1(){ 27 // int[] arr = null; 28 // System.out.println(arr[3]); 29 // } 30 31 //ArrayIndexOutOfBoundException 32 @Test 33 public void test2(){ 34 // int[] arr = new int[10]; 35 // System.out.println(arr[10]); 36 37 //StringIndexOutOfBoundException 38 // String str = "abc"; 39 // System.out.println(str.charAt(3)); 40 } 41 42 }
此为本人学习笔记,若有错误,请不吝赐教