java循环出现异常,不终止程序,继续执行

   public static void main(String[] args) {
        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");
        }
    }

打印:

 

posted @ 2022-11-11 16:33  迷糊桃  阅读(139)  评论(0编辑  收藏  举报