關(guān)于test2()方法拋出異常的問題
老師在test2()方法的最后throw了一個(gè)包裝成運(yùn)行時(shí)異常的newExc的異常,為什么test2方法聲明那里不用寫 throws RuntimeException()呢
同理test1()這里因?yàn)榉椒ɡ镉幸粋€(gè)throw new DrunkException(“喝大了”)跑出了喝大了異常,test1()方法哪里不寫throws DrunkException就回報(bào)錯,這是為什么鴨?!
老師在test2()方法的最后throw了一個(gè)包裝成運(yùn)行時(shí)異常的newExc的異常,為什么test2方法聲明那里不用寫 throws RuntimeException()呢
同理test1()這里因?yàn)榉椒ɡ镉幸粋€(gè)throw new DrunkException(“喝大了”)跑出了喝大了異常,test1()方法哪里不寫throws DrunkException就回報(bào)錯,這是為什么鴨?!
2019-03-18
舉報(bào)
2020-02-16
RuntimeException是屬于Exception的,系統(tǒng)會自動捕獲
2019-10-16
我還以為是因?yàn)閠est2用了try-catch呢
2019-03-18
剛看到了別人提的問題別人的回答解決了,RuntimeException是jvm自動捕獲的