码迷,mamicode.com
首页 > 其他好文 > 详细

异常2

时间:2016-05-28 12:42:12      阅读:110      评论:0      收藏:0      [点我收藏+]

标签:

 1     public static void main(String[] args) {
 2         for (int i = 0; i < 4; i++) {
 3             int k;
 4             switch (i) {
 5             case 0:
 6                 try {
 7                     int zero = 0;
 8                     k = 911 / zero;
 9 
10                 } catch (Exception ex) {
11                     System.out.println("算数异常 ,分母不能为零" + ex.getMessage());
12                 }
13                 break;
14             case 1:
15                 try {
16                     int[] b = null;
17                     k = b[0];
18                 } catch (Exception ex) {
19                     System.out.println("空指令异常" + ex.getMessage());
20                 }
21                 break;
22             case 2:
23                 try {
24                     int[] c = new int[2];
25                     k = c[9];
26                 } catch (Exception ex) {
27                     System.out.println("索引超出范围" + ex.getMessage());
28                 }
29                 break;
30             case 3:
31                 try {
32                     char ch = "abc".charAt(99);
33 
34                 } catch (Exception ex) {
35                     System.out.println("索引超出范围" + ex.getMessage());
36                 }
37                 break;
38             }
39 
40         }
41 
42     }

结果:

技术分享

异常2

标签:

原文地址:http://www.cnblogs.com/ouyangtangfeng99/p/5537071.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!