异常处理(题)

 1 package bao3;
 2 
 3 public class TestException {
 4     public static void main(String[] args) {
 5         for (int i = 0; i < 1; i++) {
 6             int k;
 7             
 8             switch (i) 
 9             {
10             case 0:
11                 try{
12                 int zero = 0;
13                 k = 911 / zero;
14                 break;
15                 }
16                 
17                 catch(Exception e)
18                 {
19                     e.printStackTrace();
20                     System.out.println("运行出现异常"+e.getMessage());
21                 }
22                 
23             case 1:
24                 try{
25                 int b[] = null;
26                 k = b[0];
27                 break;
28                 }
29                 
30                 catch(Exception e)
31                 {
32                     e.printStackTrace();
33                     System.out.println("运行出现异常"+e.getMessage());
34                 }
35                 
36             case 2:
37                 try{
38                 int c[] = new int[2];
39                 k = c[9];
40                 break;
41                 }
42                 
43                 catch(Exception e)
44                 {
45                     e.printStackTrace();
46                     System.out.println("运行出现异常"+e.getMessage());
47                 }
48                 
49             case 3:
50                 try{
51                 char ch = "abc".charAt(99);
52                 break;
53                 }
54                 
55                 catch(Exception e)
56                 {
57                     e.printStackTrace();
58                     System.out.println("运行出现异常"+e.getMessage());
59                 }
60             }
61         }
62     }
63 //题目:编写TestException.java程序,主方法中有以下代码,确定其中可能出现的异常,进行捕获处理。
64 }

 

posted @ 2016-05-28 19:13  明天会更好!!!!  阅读(127)  评论(0)    收藏  举报