正在加载图片...
hapter 9: Error Handling with Except public class ExtraFeatures rivate static test monitor new Test ( public static void f() throws My Exception2 t System. out. println("Throwing MyException2 from f()") throw new MyException2() public static void g( throws MyException2 System. out. println("Throwing MyException2 from g()") throw new MyException2(originate public static void h( throws MyException2 k System.out. println("Throwing MyException2 from h()",47 public static void main(String[] args)t f() t catch(MyException2 e)( gO ch (MyException2 e) e print stackTrace( try i h() e print stackTrace() ystemerr println("e. val()=#+e. val() monitor. expect (new String[] t Throwing My Exception2 from f() "MyException2: Detail Message: 0 null 号号 tat ExtraFeatures.f\\(.*\)”, 号号\ tat ExtraFeatures.main\\(.*\\)”, Throwing MyException2 from g(), MyException2: Detail Message: 0 Originated in g()", 号号\ tat ExtraFeatures,g\\(.*\) 号号\ tat ExtraFeatures.main\\(.*\\)", Throwing MyException2 from h() MyException2: Detail Message: 47 Originated 号号\ tat Extrafeatures.h\\(.*1) 号号\ tat Extrafeatures.main\(.*\\)", }); ///:~ 这个异常加了一个数据成员i,一个能读取这个数据的方法和能设定这个 数据的构造函数。此外为了能产生一些更有意思的详细信息,它还覆写了 第8页共8页 www.wgqqh.com/shhgs/tij.html email:shhgs@sohu.comChapter 9: Error Handling with Exceptions www.wgqqh.com/shhgs/tij.html email:shhgs@sohu.com ✞ 8 ✟ ✠ 8 ✟ public class ExtraFeatures { private static Test monitor = new Test(); public static void f() throws MyException2 { System.out.println("Throwing MyException2 from f()"); throw new MyException2(); } public static void g() throws MyException2 { System.out.println("Throwing MyException2 from g()"); throw new MyException2("Originated in g()"); } public static void h() throws MyException2 { System.out.println("Throwing MyException2 from h()"); throw new MyException2("Originated in h()", 47); } public static void main(String[] args) { try { f(); } catch(MyException2 e) { e.printStackTrace(); } try { g(); } catch(MyException2 e) { e.printStackTrace(); } try { h(); } catch(MyException2 e) { e.printStackTrace(); System.err.println("e.val() = " + e.val()); } monitor.expect(new String[] { "Throwing MyException2 from f()", "MyException2: Detail Message: 0 null", "%% \tat ExtraFeatures.f\\(.*\\)", "%% \tat ExtraFeatures.main\\(.*\\)", "Throwing MyException2 from g()", "MyException2: Detail Message: 0 Originated in g()", "%% \tat ExtraFeatures.g\\(.*\\)", "%% \tat ExtraFeatures.main\\(.*\\)", "Throwing MyException2 from h()", "MyException2: Detail Message: 47 Originated in h()", "%% \tat ExtraFeatures.h\\(.*\\)", "%% \tat ExtraFeatures.main\\(.*\\)", "e.val() = 47" }); } } ///:~ R\èZą^\QV͒ i#^\'Á‡R\QV@n³'ueR\ QVstuQš…'©ü^2ó-âö GH#9³+…
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有