課程
/后端開發
/Java
/Java入門第三季
newExc是什么意思?從哪里來的?好像沒有定義過啊??!
2016-07-23
源自:Java入門第三季 1-7
正在回答
public class test_1 {?? ?public static void main(String[] args) {?? ??? ?test_1 result = new test_1();?? ??? ?result.deal2();?? ?}?? ?public class DIYException1 extends Exception {?? ??? ?public DIYException1() {?? ??? ?}?? ?}?? ?public class DIYException2 extends Exception {?? ??? ?public DIYException2() {?? ??? ?}?? ?}?? ?//自定義兩種異常?? ?public void test() throws DIYException1 {?? ??? ?throw new DIYException1();?? ?}?? ?//通過test(),拋出異常1?? ?public void deal1() throws DIYException2 {?? ??? ?try {?? ??? ??? ?test();?? ??? ?} catch (DIYException1 e) {?? ??? ??? ?System.out.println("error1");?? ??? ??? ?throw new DIYException2();?? ??? ?}?? ??? ?}?? ?//檢測到異常1拋出后,拋出異常2,并輸出error1?? ?public void deal2() {?? ??? ?try {?? ??? ??? ?deal1();?? ??? ?} catch (DIYException2 e) {?? ??? ??? ?System.out.println("error2");?? ??? ?}?? ?}?? ?//檢測到異常2后,輸出error2}
.initCause()是Exception中封裝好的一些方法
newExc.initCause(e);是用來干什么的?
新的RuntimeException就叫做newExc,文中有定義:RuntimeException newExc=new RuntimeException,新的newExc是用來接收上個文件傳進來的異常的.
舉報
Java中你必須懂得常用技能,不容錯過的精彩,快來加入吧
3 回答Throw newExc; 是拋去哪里了。
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2016-07-23
public class test_1 {
?? ?public static void main(String[] args) {
?? ??? ?test_1 result = new test_1();
?? ??? ?result.deal2();
?? ?}
?? ?public class DIYException1 extends Exception {
?? ??? ?public DIYException1() {
?? ??? ?}
?? ?}
?? ?public class DIYException2 extends Exception {
?? ??? ?public DIYException2() {
?? ??? ?}
?? ?}
?? ?//自定義兩種異常
?? ?public void test() throws DIYException1 {
?? ??? ?throw new DIYException1();
?? ?}
?? ?//通過test(),拋出異常1
?? ?public void deal1() throws DIYException2 {
?? ??? ?try {
?? ??? ??? ?test();
?? ??? ?} catch (DIYException1 e) {
?? ??? ??? ?System.out.println("error1");
?? ??? ??? ?throw new DIYException2();
?? ??? ?}?? ?
?? ?}
?? ?//檢測到異常1拋出后,拋出異常2,并輸出error1
?? ?public void deal2() {
?? ??? ?try {
?? ??? ??? ?deal1();
?? ??? ?} catch (DIYException2 e) {
?? ??? ??? ?System.out.println("error2");
?? ??? ?}
?? ?}
?? ?//檢測到異常2后,輸出error2
}
.initCause()是Exception中封裝好的一些方法
2016-07-23
newExc.initCause(e);是用來干什么的?
2016-07-23
新的RuntimeException就叫做newExc,文中有定義:RuntimeException newExc=new RuntimeException,新的newExc是用來接收上個文件傳進來的異常的.