1 public class Test69 { 2 public static void main (String [] args){ 3 Test69 t69 = new Test69(); 4 try { 5 t69.run(4, 5); 6 } 7 catch (MyException e){ 8 } 9 } 10 11 public void run(int x, int y) throws MyException{ 12 if (x < y){ 13 throw new MyException("my exception from outer"); 14 } 15 else { 16 System.out.println(x); 17 } 18 Inner in = new Inner(); 19 in.run(8, 7); 20 } 21 22 public class MyException extends Throwable { 23 public MyException(String s){ 24 super(s); 25 } 26 } 27 28 public class Inner { 29 public void run(int x, int y) throws MyException{ 30 if (x < y) throw new MyException("x too small"); 31 else { 32 x = x - y; 33 } 34 } 35 } 36 } 37 | Popular Tags |