package second; public class C { public static void main(String[] args){ String name = null;//定义一个null的字符串 int name_len = 0; try{ name_len = name.length();//由于name为null,这里程序会爆出NullPointerException的异常 }catch(NullPointerException e){//捕获异常 System.out.println(e.getStackTrace()); System.out.println("程序异常了!"); }catch(Exception e){ System.out.println(e.getStackTrace()); } System.out.println(name_len); } }