欧美成人午夜免费全部完,亚洲午夜福利精品久久,а√最新版在线天堂,另类亚洲综合区图片小说区,亚洲欧美日韩精品色xxx

扣丁學(xué)堂Java在線教程之finally 一定會(huì)執(zhí)行(實(shí)例代碼)

2018-05-04 13:10:06 1786瀏覽

本篇文章小編和大家分享一篇finally 一定會(huì)執(zhí)行(實(shí)例代碼),小編覺(jué)得對(duì)學(xué)習(xí)Java開(kāi)發(fā)技術(shù)感興趣的小伙伴會(huì)有幫助,因此分享給小伙伴們,想要參加Java培訓(xùn)或者是對(duì)Java感興趣的小伙伴可以了解一下。



扣丁學(xué)堂Java在線教程之finally 一定會(huì)執(zhí)行(實(shí)例代碼)




如下所示:


class Exc{
 int a;
 int b;
}
 
 
public class Except {
 @SuppressWarnings("finally")
 static int compute (){
 Exc e = new Exc();
 e.a = 10;
 e.b = 10;
 int res = 0 ;
 try{
  res = e.a / e.b;
  System.out.println("try ……");
  return res + 1;
  
 }catch(NullPointerException e1){
  System.out.println("NullPointerException occured");
 }catch(ArithmeticException e1){
  System.out.println("ArithmeticException occured");
 }catch(Exception e3){
  System.out.println("Exception occured");
 }finally{
  System.out.println("finnaly occured");
 }
 System.out.println(res);
  
 return res+3;
 }
 
 public static void main(String[] args){
 int b = compute();
 System.out.println("mian b= "+b);
 }
}



輸出:


try ……
finnaly occured
mian b= 2



結(jié)論: 如果沒(méi)有異常, 則執(zhí)行try 中的代碼塊,直到 try 中的 return,接著執(zhí)行 finally 中的代碼塊,finally 執(zhí)行完后 , 回到try 中執(zhí)行 return 。退出函數(shù)。


class Exc{
 int a;
 int b;
}
 
 
public class Except {
 @SuppressWarnings("finally")
 static int compute (){
 Exc e = new Exc();
// e.a = 10;
// e.b = 10;
 int res = 0 ;
 try{
  res = e.a / e.b;
  System.out.println("try ……");
  return res + 1;
  
 }catch(NullPointerException e1){
  System.out.println("NullPointerException occured");
 }catch(ArithmeticException e1){
  System.out.println("ArithmeticException occured");
 }catch(Exception e3){
  System.out.println("Exception occured");
 }finally{
  System.out.println("finnaly occured");
 }
 System.out.println(res);
  
 return res+3;
 }
 
 public static void main(String[] args){
 int b = compute();
 System.out.println("mian b= "+b);
 }
}



輸出:


ArithmeticException occured
finnaly occured
0
mian b= 3



結(jié)論: 如果try 中有異常, 則在異常語(yǔ)句處,跳轉(zhuǎn)到catch 捕獲的異常代碼塊, 執(zhí)行完 catch 后,再執(zhí)行 finally ,跳出 try{}catch{}finally{} ,繼續(xù)向下執(zhí)行,不會(huì)去執(zhí)行try中 后面的語(yǔ)句。



以上就是小編給大家分享的finally 一定會(huì)執(zhí)行(實(shí)例代碼),想要了解更多內(nèi)容的小伙伴們可以登錄扣丁學(xué)堂官網(wǎng)查詢更多的內(nèi)容??鄱W(xué)堂Java在線學(xué)習(xí)是業(yè)內(nèi)知名的培訓(xùn)機(jī)構(gòu),扣丁學(xué)堂不僅有專業(yè)的老師和與時(shí)俱進(jìn)的課程體系,還有大量的Java在線教程供學(xué)員觀看學(xué)習(xí)。喜歡Java,想要學(xué)習(xí)Java開(kāi)發(fā)的小伙伴們快快行動(dòng)吧。Java技術(shù)交流群:670348138。



關(guān)注微信公眾號(hào)獲取更多學(xué)習(xí)資料

關(guān)注微信公眾號(hào)獲取更多學(xué)習(xí)資料



查看更多關(guān)于“Java開(kāi)發(fā)資訊”的相關(guān)文章>>



標(biāo)簽: 扣丁學(xué)堂Java在線教程之finally 一定 Java培訓(xùn) Java基礎(chǔ)教程 Java學(xué)習(xí)視頻 Java教學(xué)視頻 java入門教程 Java教程視頻 java在線學(xué)習(xí) java在線視頻 java在線教程

熱門專區(qū)

暫無(wú)熱門資訊

課程推薦

微信
微博
15311698296

全國(guó)免費(fèi)咨詢熱線

郵箱:codingke@1000phone.com

官方群:148715490

北京千鋒互聯(lián)科技有限公司版權(quán)所有   北京市海淀區(qū)寶盛北里西區(qū)28號(hào)中關(guān)村智誠(chéng)科創(chuàng)大廈4層
京ICP備2021002079號(hào)-2   Copyright ? 2017 - 2022
返回頂部 返回頂部