OSDN Git Service

original
[gb-231r1-is01/Gingerbread_2.3.3_r1_IS01.git] / dalvik / dx / tests / 067-dex-switch-and-try / Blort.java
1 /*
2  * Copyright (C) 2007 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 public class Blort
18 {
19     static public void blort() {
20         // This space intentionally left blank.
21     }
22
23     // This test has a try-catch but the try code can't possibly throw.
24     public int test1(int x) {
25         try {
26             switch (x) {
27                 case 1: {
28                     x = 10;
29                     break;
30                 }
31                 case 2: {
32                     x = 20;
33                     break;
34                 }
35             }
36         } catch (RuntimeException ex) {
37             // Ignore it.
38         }
39
40         return x;
41     }
42
43     // This test has a try-catch where the try code can theoretically throw.
44     public int test2(int x) {
45         try {
46             switch (x) {
47                 case 1: {
48                     x = 10;
49                     blort();
50                     break;
51                 }
52                 case 2: {
53                     x = 20;
54                     break;
55                 }
56             }
57         } catch (RuntimeException ex) {
58             // Ignore it.
59         }
60
61         return x;
62     }
63
64     // This test has a switch with a case that has a try-catch where
65     // the try code can theoretically throw, but it would be caught
66     // inside the case itself.
67     public int test3(int x) {
68         switch (x) {
69             case 1: {
70                 try {
71                     x = 10;
72                     blort();
73                 } catch (RuntimeException ex) {
74                     // Ignore it.
75                 }
76                 break;
77             }
78             case 2: {
79                 x = 20;
80                 break;
81             }
82         }
83
84         return x;
85     }
86
87     // This test has a try-catch that has a switch with a case that
88     // has a try-catch where the try code can theoretically throw, but
89     // it would be caught inside the case itself, so the outer
90     // exception handler should be considered dead.
91     public int test4(int x) {
92         try {
93             switch (x) {
94                 case 1: {
95                     try {
96                         x = 10;
97                         blort();
98                     } catch (RuntimeException ex) {
99                         // Ignore it.
100                     }
101                     break;
102                 }
103                 case 2: {
104                     x = 20;
105                     break;
106                 }
107             }
108         } catch (RuntimeException ex) {
109             return 4;
110         }
111
112         return x;
113     }
114 }