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

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

自定義異常的使用

package ImoocException;


public class my_Exception extends Exception {

/**

*?

*/

private static final long serialVersionUID = 1L;

public my_Exception() {

System.out.println("使用了這個(gè)自定義的類1!");

}

public my_Exception(String str) {

super(str);

System.out.println("使用了這個(gè)自定義的類2!");

}

public void devide(int a,int b) throws Exception {

if(b==0) {

throw new my_Exception("被除數(shù)不能為0");

}

else {

System.out.println("it is ok!");

}

}

public static void main(String[] args)throws Exception {

// TODO Auto-generated method stub

ImoocException ?imooc=new ImoocException ();

try {

imooc.devide(10, 0);

}

catch(my_Exception e) {

? ?System.out.println("異常拋出!");

}

}


}


最后結(jié)果還是出來(lái)

Exception in thread "main" java.lang.Exception

at ImoocException.ImoocException.devide(ImoocException.java:6)

at ImoocException.my_Exception.main(my_Exception.java:29)

這是怎么回事?

正在回答

2 回答

public static void main(String[] args)throws Exception 這里拋出異常??

mian方法是程序的起點(diǎn)? 在拋出只能交給JVM處理? 相當(dāng)于自己沒(méi)有捕獲異常? 沒(méi)有寫(xiě)try---catch

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

public static void main(String[] args)throws Exception

這里不需要拋異常了吧

public void devide(int a,int b) throws Exception 是不是要改成這樣

public void devide(int a,int b) throws my_Exception


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

舉報(bào)

0/150
提交
取消
Java入門(mén)第三季
  • 參與學(xué)習(xí)       409767    人
  • 解答問(wèn)題       4521    個(gè)

Java中你必須懂得常用技能,不容錯(cuò)過(guò)的精彩,快來(lái)加入吧

進(jì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)