From c6e49f267d070e7b5ff6dce89736796c2ee287f4 Mon Sep 17 00:00:00 2001 From: xuxin <840198532@qq.com> Date: Mon, 3 Aug 2026 15:44:15 +0800 Subject: [PATCH] =?UTF-8?q?s-day05-=E5=BC=82=E5=B8=B8=E7=9A=84=E4=BB=8B?= =?UTF-8?q?=E7=BB=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/com/inmind/exception01/Demo01.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 s-day05/src/com/inmind/exception01/Demo01.java diff --git a/s-day05/src/com/inmind/exception01/Demo01.java b/s-day05/src/com/inmind/exception01/Demo01.java new file mode 100644 index 0000000..be86ff8 --- /dev/null +++ b/s-day05/src/com/inmind/exception01/Demo01.java @@ -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("程序结束"); + } +}