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 {
maybeThrow(int x)19     public static int maybeThrow(int x) {
20         if (x < 10) {
21             throw new RuntimeException();
22         }
23 
24         return x;
25     }
26 
exTest1(int x)27     public static int exTest1(int x) {
28         try {
29             maybeThrow(x);
30             return 1;
31         } catch (RuntimeException ex) {
32             return 2;
33         }
34     }
35 
exTest2(int x)36     public static int exTest2(int x) {
37         try {
38             x++;
39             x = maybeThrow(x);
40         } catch (RuntimeException ex) {
41             return 1;
42         }
43 
44         // Since the code in the try block can't possibly throw, there
45         // should not be a catch in the final result.
46         try {
47             x++;
48         } catch (RuntimeException ex) {
49             return 2;
50         }
51 
52         try {
53             return maybeThrow(x);
54         } catch (RuntimeException ex) {
55             return 3;
56         }
57     }
58 }
59