blob: 28442f348f8a5c81626135578d49d84daf75ebb3 [file] [log] [blame]
Christoffer Quist Adamsen28ece0f2018-06-07 09:16:04 +02001// Copyright (c) 2018, 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
5package classmerging;
6
7public class ExceptionTest {
8 public static void main(String[] args) {
9 // The following will lead to a catch handler for ExceptionA, which is merged into ExceptionB.
10 try {
Christoffer Quist Adamsen95dd66b2018-06-11 09:12:45 +020011 doSomethingThatMightThrowExceptionB();
12 doSomethingThatMightThrowException2();
13 } catch (ExceptionB exception) {
14 System.out.println("Caught exception: " + exception.getMessage());
Christoffer Quist Adamsen28ece0f2018-06-07 09:16:04 +020015 } catch (ExceptionA exception) {
16 System.out.println("Caught exception: " + exception.getMessage());
Christoffer Quist Adamsen95dd66b2018-06-11 09:12:45 +020017 } catch (Exception2 exception) {
18 System.out.println("Caught exception: " + exception.getMessage());
19 } catch (Exception1 exception) {
20 System.out.println("Caught exception: " + exception.getMessage());
Christoffer Quist Adamsen28ece0f2018-06-07 09:16:04 +020021 }
22 }
23
Christoffer Quist Adamsen95dd66b2018-06-11 09:12:45 +020024 private static void doSomethingThatMightThrowExceptionB() throws ExceptionB {
25 throw new ExceptionB("Ouch!");
26 }
27
28 private static void doSomethingThatMightThrowException2() throws Exception2 {
29 throw new Exception2("Ouch!");
30 }
31
Christoffer Quist Adamsen28ece0f2018-06-07 09:16:04 +020032 // Will be merged into ExceptionB when class merging is enabled.
33 public static class ExceptionA extends Exception {
34 public ExceptionA(String message) {
35 super(message);
36 }
37 }
38
39 public static class ExceptionB extends ExceptionA {
40 public ExceptionB(String message) {
41 super(message);
42 }
43 }
Christoffer Quist Adamsen95dd66b2018-06-11 09:12:45 +020044
45 public static class Exception1 extends Exception {
46 public Exception1(String message) {
47 super(message);
48 }
49 }
50
51 public static class Exception2 extends Exception1 {
52 public Exception2(String message) {
53 super(message);
54 }
55 }
Christoffer Quist Adamsen28ece0f2018-06-07 09:16:04 +020056}