标签:cat 语句 抛出异常 col ring rom blog 执行 检查
1 public static int NoException(){ 2 int i=10; 3 try{ 4 System.out.println("i in try block is:"+i); 5 return --i; 6 } 7 catch(Exception e){ 8 --i; 9 System.out.println("i in catch - form try block is:"+i); 10 return --i; 11 } 12 finally{ 13 System.out.println("i in finally - from try or catch block is:"+i); 14 return --i; 15 } 16 }
1 public static void main(String[] args) { 2 System.out.println("=============NoException=================="); 3 System.out.println(NoException()); 4 System.out.println("==============================="); 5 }
1 =============NoException================== 2 i in try block is:10 3 i in finally - from try or catch block is:9 4 8 5 ===============================
1 public static int NoException1(){ 2 int i=10; 3 try{ 4 System.out.println("i in try block is:"+i); 5 return --i; 6 } 7 catch(Exception e){ 8 --i; 9 System.out.println("i in catch - form try block is:"+i); 10 return --i; 11 } 12 finally{ 13 System.out.println("i in finally - from try or catch block is:"+i); 14 --i; 15 System.out.println("i in finally block is:"+i); 16 //return --i; 17 } 18 }
1 =============NoException1================== 2 i in try block is:10 3 i in finally - from try or catch block is:9 4 i in finally block is:8 5 9 6 ===============================
1 public static int WithException(){ 2 int i=10; 3 try{ 4 System.out.println("i in try block is:"+i); 5 i = i/0; 6 return --i; 7 } 8 catch(Exception e){ 9 System.out.println("i in catch - form try block is:"+i); 10 --i; 11 System.out.println("i in catch block is:"+i); 12 return --i; 13 } 14 finally{ 15 System.out.println("i in finally - from try or catch block is--"+i); 16 --i; 17 System.out.println("i in finally block is--"+i); 18 return --i; 19 } 20 }
1 =============WithException================== 2 i in try block is:10 3 i in catch - form try block is:10 4 i in catch block is:9 5 i in finally - from try or catch block is--8 6 i in finally block is--7 7 6 8 ===============================
1 public static int WithException1(){ 2 int i=10; 3 try{ 4 System.out.println("i in try block is:"+i); 5 i=i/0; 6 return --i; 7 }catch(Exception e){ 8 System.out.println("i in catch - form try block is:"+i); 9 return --i; 10 }finally{ 11 12 System.out.println("i in finally - from try or catch block is:"+i); 13 --i; 14 System.out.println("i in finally block is:"+i); 15 //return i; 16 } 17 }
1 =============WithException1================== 2 i in try block is:10 3 i in catch - form try block is:10 4 i in finally - from try or catch block is:9 5 i in finally block is:8 6 9 7 ===============================
1 public static int WithException2(){ 2 int i=10; 3 try{ 4 System.out.println("i in try block is:"+i); 5 i=i/0; 6 return --i; 7 } 8 catch(Exception e){ 9 System.out.println("i in catch - form try block is:"+i); 10 int j = i/0; 11 return --i; 12 } 13 finally{ 14 15 System.out.println("i in finally - from try or catch block is:"+i); 16 --i; 17 --i; 18 System.out.println("i in finally block is:"+i); 19 return --i; 20 }
1 =============WithException2================== 2 i in try block is:10 3 i in catch - form try block is:10 4 i in finally - from try or catch block is:10 5 i in finally block is:8 6 7 7 ===============================
1 public static int WithException3(){ 2 int i=10; 3 try{ 4 System.out.println("i in try block is:"+i); 5 i=i/0; 6 //return --i; 7 } 8 catch(Exception e){ 9 System.out.println("i in catch - form try block is:"+i); 10 //int j = i/0; 11 //return --i; 12 } 13 finally{ 14 15 System.out.println("i in finally - from try or catch block is:"+i); 16 --i; 17 --i; 18 System.out.println("i in finally block is:"+i); 19 //return --i; 20 } 21 return --i; 22 }
1 =============WithException3================== 2 i in try block is:10 3 i in catch - form try block is:10 4 i in finally - from try or catch block is:10 5 i in finally block is:8 6 7 7 ===============================
try--catch--finally中return返回值执行的顺序
标签:cat 语句 抛出异常 col ring rom blog 执行 检查
原文地址:http://www.cnblogs.com/zhangboy/p/7643583.html