java遇到exception继续执行

@Test
    void contextLoads02(){
        Map<String, Object> hashMap = new HashMap<>();
        hashMap.put("a","1");
        hashMap.put("b",null);
        hashMap.put("c","3");
        for(Map.Entry<String, Object> moEntry : hashMap.entrySet()){
            try {
                boolean equals = moEntry.getValue().equals("1");
                System.out.println(moEntry.getKey() + "," + moEntry.getValue() +","+  equals);
            } catch (Exception e) {
                e.printStackTrace();
                System.out.println("异常");
                continue; //加上continue 出现异常后会执行后面的操作,打印11 ,若不加continue则不会打印11,直接进行下一个循环
            }
            System.out.println("11");
        }
    }

参考:https://blog.csdn.net/weixin_49419695/article/details/126275807

posted @ 2022-11-01 23:44  涂山树下  阅读(128)  评论(0)    收藏  举报