日期:2014-05-20 浏览次数:20790 次
public class MyException { public static void main (String[] args) { new MyException().MethodA(); } public void MethodA(){ System.out.println("Method A called!"); try{ this.MethodB(); }catch(NewException e){ System.err.println(e); System.out.println("Exception caught in Method A"); }finally{ System.out.println("Exception finally statement in Method A"); } } public void MethodB()throws NewException{ System.out.println("Method B called!"); this.MethodC(); } public void MethodC()throws NewException{ System.out.println("Method C called!"); throw new NewException(); } } class NewException extends Exception{ public String toString(){ return ("Exception throw in MyException!"); } }
public class MyException { public static void main (String[] args) { new MyException().MethodA(); } public void MethodA()[color=#FF0000]throws NewException[/color]{ System.out.println("Method A called!"); try{ this.MethodB(); }catch(NewException e){ System.err.println(e); System.out.println("Exception caught in Method A"); [color=#FF0000]throw e[/color] }finally{ System.out.println("Exception finally statement in Method A"); } } public void MethodB()throws NewException{ System.out.println("Method B called!"); this.MethodC(); } public void MethodC()throws NewException{ System.out.println("Method C called!"); throw new NewException(); } } class NewException extends Exception{ public String toString(){ return ("Exception throw in MyException!"); } }
------解决方案--------------------
public void MethodA()[color=#FF0000]throws NewException[/color]{ System.out.println("Method A called!"); try{ this.MethodB(); }catch(NewException e){ System.err.println(e); System.out.println("Exception caught in Method A"); [color=#FF0000]throw e[/color] }finally{ System.out.println("Exception finally statement in Method A"); } 这样抛出,在main方法也捕获不到吧 ????????