进阶day04-异常产生的原因以及流程
This commit is contained in:
26
javaSE-day05/src/com/inmind/throwable01/ExceptionDemo02.java
Normal file
26
javaSE-day05/src/com/inmind/throwable01/ExceptionDemo02.java
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package com.inmind.throwable01;
|
||||||
|
/*
|
||||||
|
异常产生的原因以及流程
|
||||||
|
|
||||||
|
注意:JVM在运行时发生对应的异常后,会主动创建出一个异常对象,交给当前方法处理,如果当前方法没有处理
|
||||||
|
也可以交给当前方法的调用者处理,如果没有任何方法进行异常的处理,最终异常会交给JVM
|
||||||
|
|
||||||
|
JVM收到未处理异常只做2件事情:
|
||||||
|
1.打印异常信息
|
||||||
|
2.异常终止程序
|
||||||
|
*/
|
||||||
|
public class ExceptionDemo02 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
//定义整数数组
|
||||||
|
int[] arr = {1, 2, 3, 4, 5};
|
||||||
|
//定义出一个根据索引获取指定数组空间的值
|
||||||
|
int result = getByIndex(arr,7);
|
||||||
|
System.out.println(result);
|
||||||
|
System.out.println("程序结束");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int getByIndex(int[] arr, int index) {
|
||||||
|
int result = arr[index];
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user