JDK7 中包含大量的新特性和代码风格,本代码是介绍在一个异常捕获块中同时捕获多个异常
public class Test{ public static void main (String args[]){ try { if (args[0].equals("null")) { throw (new NullPointerException()); } else { throw (new ArrayIndexOutOfBoundsException()); } } catch (NullPointerException | ArrayIndexOutOfBoundsException ex) { ex.getMessage(); } } }
原创文章,作者:奋斗,如若转载,请注明出处:https://blog.ytso.com/10195.html