java.lang.NullPointerException
at com.dream.model.ExceptionTest.test(ExceptionTest.java:17)
at com.dream.model.ExceptionTest.main(ExceptionTest.java:11)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
java.lang.StringIndexOutOfBoundsException: String index out of range: 0
at java.lang.String.charAt(String.java:695)
at com.dream.model.ExceptionTest.test(ExceptionTest.java:17)
at com.dream.model.ExceptionTest.main(ExceptionTest.java:11)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
4,4,4
第一个方法调用会报NullPointerException
第二个方法调用会报StringIndexOutOfBoundsException
第三个方法运行正常
因为有finally块,所以不论前面的运行结果是什么,都会返回4,所以会看到4,4,4这样的输出结果。