1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| public class Test { public static void main(String[] args) throws IOException { System.out.println("返回结果:"+test()); } public static int test(){ int num = 0; try { System.out.println("进入--> try "); num = 1; System.out.println("try方法--> num=" + num); int i = 1/0; return num; } catch (Exception e) { System.out.println("进入--> catch "); num = 2; System.out.println("catch方法--> num=" + num); return num; } finally { System.out.println("进入--> finally "); num = 3; System.out.println("finally方法--> num=" + num); return num; } } }
|