blob: 4b30391789a69c4df0d550ed0790043ca810b6b0 [file] [log] [blame]
Ian Zerny31054bb2017-10-10 12:12:53 +02001// Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5public class FinallyBlock {
6
7 public static int finallyBlock(Throwable obj) throws Throwable {
8 int x = 21;
9 try {
10 if (obj != null) {
11 throw obj;
12 }
13 } catch (AssertionError e) {
14 x = e.getMessage().length() + 1;
15 } catch (RuntimeException e) {
16 x = e.getMessage().length() + 2;
17 } finally {
18 x *= 2;
19 }
20 return x;
21 }
22
23 private static int callFinallyBlock(Throwable obj) {
24 try {
25 return finallyBlock(obj);
26 } catch (Throwable e) {
27 return -1;
28 }
29 }
30
31 public static void main(String[] args) throws Throwable {
32 System.out.println(callFinallyBlock(null));
33 System.out.println(callFinallyBlock(new AssertionError("assert error")));
34 System.out.println(callFinallyBlock(new RuntimeException("runtime error")));
35 System.out.println(callFinallyBlock(new Throwable("throwable")));
36 }
37}