zoukankan      html  css  js  c++  java
  • 异常练习1

     1 package Exception;
     2 
     3 public class TestException {
     4 
     5     public static void main(String[] args) {
     6         // TODO 自动生成的方法存根
     7         for(int i=0;i<4;i++){
     8             int  k;
     9             switch(i){
    10                 case 0:
    11         int zero=0;
    12         try{
    13         k=911/zero;
    14         break;
    15         }catch(Exception ex)
    16         {
    17             ex.printStackTrace();
    18             System.out.println("异常1"+ex.getMessage());
    19         }
    20         
    21         case1:
    22         try{
    23         int  b[]=null;
    24         k = b[0];
    25         break;
    26         }
    27         catch(Exception ex)
    28         {
    29             ex.printStackTrace();
    30             System.out.println("异常二"+ex.getMessage());
    31         }
    32         case2:
    33         try{            
    34         int c[]=new int[2];
    35 
    36         k=c[9];
    37         break;
    38         }
    39         catch(Exception ex)
    40         {
    41             ex.printStackTrace();
    42             System.out.println("异常三"+ex.getMessage());
    43             
    44         }
    45         case3:
    46         try{            
    47         char  ch="abc".charAt(99);
    48         }
    49         catch(Exception ex)
    50         {
    51             ex.printStackTrace();
    52             System.out.println("异常四"+ex.getMessage());
    53         }
    54         break;
    55             }
    56         }
    57         
    58 
    59     }
    60 
    61 }
  • 相关阅读:
    Careercup
    Careercup
    Careercup
    Careercup
    Careercup
    Careercup
    Careercup
    Careercup
    Careercup
    Careercup
  • 原文地址:https://www.cnblogs.com/yg6405816/p/5538493.html
Copyright © 2011-2022 走看看