- 相關(guān)推薦
Java中finally的問(wèn)題
引導(dǎo)語(yǔ):finally是終極的,那么Java中的finally又是怎樣的呢,以下是百分網(wǎng)小編分享給大家的Java中finally的問(wèn)題,歡迎閱讀!
一個(gè)比較繞的例子:
try {
try {
try {
String s = null;
s.charAt(0);
} catch(NullPointerException nu) {
System.out.println(nu);
int i = 0;
int j = 10 / i;
} finally {
System.out.println("Finally");
}
} catch(ArithmeticException e) {
System.out.println(e);
throw new IOException();
} finally {
System.out.println("Finally 2");
}
} catch(IOException ioe) {
System.out.println(ioe);
try {
return;
} finally {
System.out.println("After return");
}
}
運(yùn)行結(jié)果為:
java.lang.NullPointerException
Finally
java.lang.ArithmeticException: / by zero
Finally 2
java.io.IOException
After return
【Java中finally的問(wèn)題】相關(guān)文章:
Java中定義與聲明的區(qū)別05-21
淺談Java中的弱引用10-27
如何解決java內(nèi)存泄漏的問(wèn)題08-13
Java編程中異常處理的方法10-02
java中的4個(gè)核心概念07-15