不知道他驗證了沒。。。
package com.zjw;
/**
* @author 朱俊偉
* @date 2020/11/12 22:09
*/
public class TestError {
public static void main(String[] args) {
testWhileException();
//testForException();
System.out.println("我是main結束。。。");
}
public static void testWhileException(){
int a = 1;
int b = 2;
while (b>a){
System.out.println("我是while循環。。");
int i = 1/0;
}
}
public static void testForException(){
for (;;){
System.out.println("我是for循環。。。");
int i = 1/0;
}
}
}
根據結果發現:在循環里發生異常,如果沒有捕獲的話,異常會一直向上拋,跳出循環,下面的代碼也不會再執行。