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

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

分类:

技术点:

相关文章:

  • 2021-12-10
  • 2022-01-08
  • 2022-12-23
  • 2021-11-17
  • 2021-06-15
  • 2021-06-04
  • 2021-06-13
  • 2022-12-23
猜你喜欢
  • 2021-12-02
  • 2022-12-23
  • 2022-02-27
  • 2022-01-09
  • 2022-12-23
相关资源
相似解决方案