java异常分为ERROR和EXCEPTION
exception可以处理而error是不能处理的
package part7; public class ExceptionDemo { public static void main(String[] args) { int[]arr = {1,2,33,3}; //Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4 // at part7.ExceptionDemo.main(ExceptionDemo.java:6) 这种属于数组越界错误 //System.out.println(arr[4]); //Exception in thread "main" java.lang.OutOfMemoryError: Java heap space //at part7.ExceptionDemo.main(ExceptionDemo.java:11) 这种属于堆内存溢出 int[]arr2=new int[1024*1024*1024]; } }
检查异常是编译器可以检查出来的,程序中必须修改,不然无法编译通过
而运行时异常是程序在运行过程中产生的,编译器无法检查出来。
✳异常的处理
1.try catch finally
throws
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)