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

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

寫DrunkException的時(shí)候出現(xiàn)了一個(gè)問題:類型 serializable 類 DrunkException 未聲明類型為 long 的靜態(tài)終態(tài) serialVersionUID 字段

這個(gè)代碼有錯(cuò):

package imooc.exception.test;


public class DrunkException extends Exception {

public DrunkException() {}

public DrunkException(String message) {

super(message);

}

}

那個(gè)類那邊提示類型 serializable 類 DrunkException 未聲明類型為 long 的靜態(tài)終態(tài) serialVersionUID 字段,這是什么意思呀?

下面是ChainTest類,看看有沒有錯(cuò):

package imooc.exception.test;


public class ChainTest {


/*

* 這個(gè)類完成的工作:第一個(gè)方法(Test1):拋出“喝大了”異常;

* 第二個(gè)方法(Test2):調(diào)用Test1,捕獲“喝大了”異常,并包裝成運(yùn)行時(shí)異常,繼續(xù)拋出;

* main方法中調(diào)用test2,嘗試捕獲test2方法拋出的異常

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

ChainTest ct = new ChainTest();

try {

ct.test2();

}catch(Exception e) {

e.getStackTrace();

}

}


public void test1() throws DrunkException {

throw new DrunkException("喝車別開酒!");

}

public void test2() {?

try {

test1();

} catch (DrunkException e) {

// TODO 自動(dòng)生成的 catch 塊

//e.printStackTrace();這個(gè)就不需要了

RuntimeException newExc = new RuntimeException("司機(jī)一滴酒,親人兩行淚");//新建一個(gè)RuntimeException,起名叫newExc

newExc.initCause(e);//調(diào)用newExc的initCause方法并把捕獲的DrunkException放進(jìn)去

throw newExc;//拋出新異常

}

}

}


正在回答

1 回答

ChainTest類的main方法catch塊里e.getStackTrace();改成e.printStackTrace();
1 回復(fù) 有任何疑惑可以回復(fù)我~
#1

DrJexus 提問者

還有test2里面司機(jī)一滴酒親人兩行淚這句話在演示案例中改成了e,這是為什么呢?
2019-08-27 回復(fù) 有任何疑惑可以回復(fù)我~
#2

無憂21st 回復(fù) DrJexus 提問者

catch塊里是DrunkException對(duì)象 e是DrunkException對(duì)象返回的錯(cuò)誤信息 司機(jī)一滴酒,親人兩行淚這段話不也是錯(cuò)誤提示信息嘛,用e替換了而已
2019-08-27 回復(fù) 有任何疑惑可以回復(fù)我~
#3

無憂21st 回復(fù) DrJexus 提問者

e是錯(cuò)誤信息對(duì)象
2019-08-27 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

寫DrunkException的時(shí)候出現(xiàn)了一個(gè)問題:類型 serializable 類 DrunkException 未聲明類型為 long 的靜態(tài)終態(tài) serialVersionUID 字段

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

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

幫助反饋 APP下載

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

公眾號(hào)

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