s-day05-异常产生的原因以及流程
This commit is contained in:
@@ -1,8 +1,22 @@
|
||||
package com.inmind.exception01;
|
||||
|
||||
|
||||
/*
|
||||
异常的分类:
|
||||
1.编译时异常(checked异常):继承Exception的异常,跟RuntimeException无关的异常,都是编译时异常
|
||||
2.运行时异常(unChecked异常):只要是RuntimeException或它的子类,都是运行时异常
|
||||
*/
|
||||
public class Demo02 {
|
||||
public static void main(String[] args) {
|
||||
int[] arr = {1, 2, 3, 4, 5};
|
||||
//调用一个方法,获取数组指定索引的值
|
||||
int value = getValue1(arr,10);
|
||||
System.out.println(value);
|
||||
System.out.println("程序结束");
|
||||
}
|
||||
|
||||
private static int getValue1(int[] arr, int index) {
|
||||
int value = arr[index];//JVM创建了索引越界异常,交给当前方法处理
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user