關(guān)于eclipse報(bào)錯(cuò)的原因
package?com.imooc.six; public?class?ChainTest?{ /* ?*?test1():拋出“喝大了”異常 ?*?test2():調(diào)用test1(),捕獲“喝大了”異常,并且包裝成運(yùn)行時(shí)異常,繼續(xù)拋出 ?*?main方法中,調(diào)用test2(),嘗試捕獲test2()方法拋出的異常 ?*/ public?static?void?main(String[]?args)?{ ChainTest?ct?=?new?ChainTest(); try{ ct.test2(); }catch(Exception?e){ e.printStackTrace(); } public?void?test1()?throws?DrunkException{ throw?new?DrunkException("喝車別開酒"); } public?void?test2(){ try{ test1(); }catch(DrunkException?e){ RuntimeException?newExc?=?new?RuntimeException("司機(jī)一滴酒,親人兩行淚"); //運(yùn)行時(shí)異常(調(diào)用RuntimeException的含參構(gòu)造器) newExc.initCause(e);//對(duì)異常進(jìn)行包裝 throw?newExc; } } } }
在兩個(gè)方法名的地方??void test1() 和test2()
eclipse都提示報(bào)錯(cuò),不明白錯(cuò)誤在哪里,求教~
2017-07-06
你把這兩個(gè)方法寫在主方法里了,方法套方法能對(duì)嗎,把這兩個(gè)方法放到主方法外面類里邊