2019-01-16 13:45:00 1250瀏覽
今天扣丁學(xué)堂Java培訓(xùn)老師給大家介紹一下關(guān)于Java異常處理與throws關(guān)鍵字用法分析詳解,首先在Java異常處理的時(shí)候,我們先來(lái)認(rèn)識(shí)一下異常和一些案例!
Exc e=null; System.out.println(e.i);
int a=10; int b=0; System.out.println(a/b);
try{ 異常語(yǔ)句; } catch(Exception e){ } finally{ 一定會(huì)執(zhí)行的代碼; }
int a=10; int b=0; try { System.out.println(a/b); } catch (ArithmeticException e){ System.out.println(e); }
int temp=0; Exc e=null; try { temp=e.a/e.b; System.out.println(temp); } catch (NullPointerException e1){ System.out.println("空指針異常"+e1); } catch (ArithmeticException e1){ System.out.println("算數(shù)異常"+e1); } finally { System.out.println("程序退出"); }
public void tell()throws Exception{}
public static void main(String [] args){ try { tell(10,0); } catch (Exception e){ System.out.println(e); } } public static void tell(int i,int j)throws ArithmeticException{ int temp=0; temp=i/j; System.out.println(temp); }
public static void main(String [] args)throws Exception{ tell(10,0); } public static void tell(int i,int j)throws ArithmeticException{ int temp=0; temp=i/j; System.out.println(temp); }
此時(shí),最后拋給JVM進(jìn)行處理,以上就是關(guān)于扣丁學(xué)堂Java培訓(xùn)之異常處理與throws關(guān)鍵字用法分析的詳細(xì)介紹,希望對(duì)大家的學(xué)習(xí)有所幫助,請(qǐng)關(guān)注扣丁學(xué)堂Java培訓(xùn)官網(wǎng)、微信等平臺(tái),扣丁學(xué)堂IT職業(yè)在線學(xué)習(xí)教育平臺(tái)不僅為您提供權(quán)威的Java視頻教程供大家學(xué)習(xí),還精心的準(zhǔn)備了Java從入門到精通開(kāi)發(fā)實(shí)戰(zhàn)技能,定能讓你學(xué)有所成。扣丁學(xué)堂Java技術(shù)交流群:670348138。
【關(guān)注微信公眾號(hào)獲取更多學(xué)習(xí)資料】
查看更多關(guān)于“Java開(kāi)發(fā)資訊”的相關(guān)文章>>