try catch throw理解:
1.try catch不跟throw则后续代码继续执行。
2.ry catch跟throw则后续代码不会执行。
过程一:"抛":程序在正常执行的过程中,一旦出现异常,就会在异常代码处生成一个对应异常类的对象。
* 并将此对象抛出。
* 一旦抛出对象以后,其后的代码就不再执行。
*
* 关于异常对象的产生:① 系统自动生成的异常对象
* ② 手动的生成一个异常对象,并抛出(throw)
package com.zte.Exception;
import org.junit.Test;
public class TestException {
@Test
public void test() {
int i = 1;
int m = 0;
int[] arr = new int[10];
try {
int s = i / m;
System.out.println("------------------1");
} catch (Exception e) {
e.printStackTrace();
//throw new ArithmeticException("异常1");
}
try {
System.out.println("----------------------2");
arr[10] = 1;
System.out.println("----------------------3");
} catch (Exception e) {
System.out.println("---------------------4");
e.printStackTrace();
throw new ArrayIndexOutOfBoundsException("异常2角标溢出");
}
System.out.println("继续执行");
}
}