第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

網(wǎng)上看到這段代碼,沒(méi)有像課里講的一樣產(chǎn)生異常鏈?

public?class?TestException?{??

????public?TestException()?{??

????}??

??

????boolean?testEx()?throws?Exception?{??

????????boolean?ret?=?true;??

????????try?{??

????????????ret?=?testEx1();??

????????}?catch?(Exception?e)?{??

????????????System.out.println("testEx,?catch?exception");??

????????????ret?=?false;??

????????????throw?e;??

????????}?finally?{??

????????????System.out.println("testEx,?finally;?return?value="?+?ret);??

????????????return?ret;??

????????}??

????}??

??

????boolean?testEx1()?throws?Exception?{??

????????boolean?ret?=?true;??

????????try?{??

????????????ret?=?testEx2();??

????????????if?(!ret)?{??

????????????????return?false;??

????????????}??

????????????System.out.println("testEx1,?at?the?end?of?try");??

????????????return?ret;??

????????}?catch?(Exception?e)?{??

????????????System.out.println("testEx1,?catch?exception");??

????????????ret?=?false;??

????????????throw?e;??

????????}?finally?{??

????????????System.out.println("testEx1,?finally;?return?value="?+?ret);??

????????????return?ret;??

????????}??

????}??

??

????boolean?testEx2()?throws?Exception?{??

????????boolean?ret?=?true;??

????????try?{??

????????????int?b?=?12;??

????????????int?c;??

????????????for?(int?i?=?2;?i?>=?-2;?i--)?{??

????????????????c?=?b?/?i;??

????????????????System.out.println("i="?+?i);??

????????????}??

????????????return?true;??

????????}?catch?(Exception?e)?{??

????????????System.out.println("testEx2,?catch?exception");??

????????????ret?=?false;??

????????????throw?e;??

????????}?finally?{??

????????????System.out.println("testEx2,?finally;?return?value="?+?ret);??

????????????return?ret;??

????????}??

????}??

??

????public?static?void?main(String[]?args)?{??

????????TestException?testException1?=?new?TestException();??

????????try?{??

????????????testException1.testEx();??

????????}?catch?(Exception?e)?{??

????????????e.printStackTrace();??

????????}??

????}??

} ?

代碼輸出結(jié)果是:

i=2
i=1
testEx2, catch exception
testEx2, finally; return value=false
testEx1, finally; return value=false
testEx, finally; return value=false

?不明白的是為什么testEx1和testEx都沒(méi)有捕獲到異常。

正在回答

3 回答

你throw了一個(gè)異常,然后finally中又返回了一個(gè)值,相當(dāng)于方法正常結(jié)束,所以異常就沒(méi)了。finally中不要加return。

1 回復(fù) 有任何疑惑可以回復(fù)我~
#1

云與米修 提問(wèn)者

原來(lái)是這么回事,明白了,謝謝。
2016-04-08 回復(fù) 有任何疑惑可以回復(fù)我~
#2

我真的不知道要取什么名字

是不是說(shuō),我已經(jīng)用這個(gè)聲明的異常加finally已經(jīng)解決了代碼中的問(wèn)題,讓程序正常運(yùn)行,就不出現(xiàn)異常。
2016-05-31 回復(fù) 有任何疑惑可以回復(fù)我~

boolean?ret?=?true;??

????????try?{??

????????????ret?=?testEx2();??

????????????if?(!ret)?{??

????????????????return?false;??

????????????}??

????????????System.out.println("testEx1,?at?the?end?of?try");??

????????????return?ret; ?

這段代碼的意思是定義ret為真,如果testEx2(); 返回值為假,則拋出異常

0 回復(fù) 有任何疑惑可以回復(fù)我~

這個(gè)程序的輸出順序是先testEx2,再testEx,最后testEx。而為什么視頻上程序的輸出順序是先test2,再text1?和什么有關(guān)

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

網(wǎng)上看到這段代碼,沒(méi)有像課里講的一樣產(chǎn)生異常鏈?

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)