s-day05-异常的介绍

This commit is contained in:
2026-08-03 15:44:15 +08:00
parent 74668150e1
commit c6e49f267d
@@ -0,0 +1,27 @@
package com.inmind.exception01;
/*
异常:程序运行时,会产生的一些问题或者错误。
在java中有一个类专门来表示错误和异常,Throwable
Throwable类是Java语言中所有错误和异常的超类。
Throwable分类:
1.错误 Error,表示程序发生不可挽救的错误。
2.异常Exception,表示程序发生轻微问题,可以处理。
*/
public class Demo01 {
public static void main(String[] args) {
int[] arr = {1, 2, 3, 4, 5, 6, 7, 8};
if (arr.length >= 6) {
System.out.println(arr[5]);//ArrayIndexOutOfBoundsException
}
/*int[] arr1 = new int[10000*1000*1000];
int[] arr2 = new int[10000*1000*1000];
int[] arr3 = new int[10000*1000*1000];
int[] arr4 = new int[10000*1000*1000];
OutOfMemoryError:内存溢出,内存只有8G,但是我申请了超出8G的数组空间,就会报内存溢出的错误
*/
System.out.println("程序结束");
}
}