java抛出异常后 代码继续运行问题探究

java抛出异常后 代码继续运行问题探究

1、

package com.baofoo.admin.test;

import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

/**
 * Created by BF100 on 2018/4/12.
 */
@Slf4j
public class TestByCaoxNew {
    @Test
    public void test1(){
        try{
            int a = 1/0;
            System.out.println("我执行了没?");
        }catch (Exception e){
            log.error("call Exception :{}",e);
            e.printStackTrace();
        }
        System.out.println("come on !!!");
    }

    @Test
    public void test2(){
        try{
            if(true) {
                throw new Exception("我要抛出异常了!!!");
            }
            //抛出异常,不会执行
            System.out.println("我执行了没?");
        }catch (Exception e){
            log.error("call Exception :{}",e);
        }
        System.out.println("我执行了 !!!");
    }
}
2.test1运行结果:


3.test2运行结果:


猜你喜欢

转载自blog.csdn.net/caox_nazi/article/details/79961588