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"); } }
打印:
本文来自博客园,作者:迷糊桃,转载请注明原文链接:https://www.cnblogs.com/mihutao/p/16880956.html