zjw-blog

不知道他验证了没。。。

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;
        }
    }
}

根据结果发现:在循环里发生异常,如果没有捕获的话,异常会一直向上抛,跳出循环,下面的代码也不会再执行。

分类:

技术点:

相关文章: