Java throws定義方法異常
提問人:劉旭39發(fā)布時(shí)間:2020-11-30
throws關(guān)鍵字用于指定方法可能拋出的異常,多個(gè)異常之間通過逗號分隔。throws拋出異常語 法定義格式為:
[訪問權(quán)限修飾符]方法返回類型方法名(參數(shù)..) throws異常類型1,異常類型2 {
//代碼塊
}
//throws定義方法異常
public class Demo {
public static void main(String[] args) throws Exception {
test();
}
private static void test() throws Exception{
throw new IlleaglArgumentException("方法內(nèi)拋出異常");
}
}

繼續(xù)查找其他問題的答案?
相關(guān)視頻回答
點(diǎn)擊加載更多評論>>