且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

java中异常注意的细节1

更新时间:2022-10-03 16:29:15

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
/* public class Test{
   public static void main(String[] args){
       int i=0;
       try{
           func();//区别就是该函数抛出的异常被封装了,外界不知道到底会不会发生该异常
           System.out.println("i = " + i++);//所以这句话是有机会执行的
       }catch(Exception e){
           System.out.println("i = " + i++);
       }
   }
    
   static void func() throws Exception{
       throw new Exception();
   }
}
 */
public class Test{
    public static void main(String[] args){
        int i=0;
        try{
           throw new Exception();
           System.out.println("i = " + i++);//完全的废话,肯定不会被执行到
        }catch(Exception e){
           System.out.println("i = " + i++);
        }
         
        System.out.println("i = " + i++);
    }
}









本文转自 小眼儿 博客园博客,原文链接:http://www.cnblogs.com/hujunzheng/p/3872643.html,如需转载请自行联系原作者