關(guān)于eclipse報錯的原因
package?com.imooc.six; public?class?ChainTest?{ /* ?*?test1():拋出“喝大了”異常 ?*?test2():調(diào)用test1(),捕獲“喝大了”異常,并且包裝成運行時異常,繼續(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("司機一滴酒,親人兩行淚"); //運行時異常(調(diào)用RuntimeException的含參構(gòu)造器) newExc.initCause(e);//對異常進行包裝 throw?newExc; } } } }
在兩個方法名的地方??void test1() 和test2()
eclipse都提示報錯,不明白錯誤在哪里,求教~
2017-07-06
你把這兩個方法寫在主方法里了,方法套方法能對嗎,把這兩個方法放到主方法外面類里邊