test/tools/javac/multicatch/Pos02.java

Mon, 26 Oct 2015 13:23:30 -0700

author
asaha
date
Mon, 26 Oct 2015 13:23:30 -0700
changeset 2999
683b3e7e05a7
parent 554
9d9f26857129
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Added tag jdk8u76-b00 for changeset 10ffafaf5340

     1 /*
     2  * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  */
    24 /*
    25  * @test
    26  * @bug 6943289
    27  * @summary Project Coin: Improved Exception Handling for Java (aka 'multicatch')
    28  *
    29  */
    31 public class Pos02 {
    33     static class A extends Exception {}
    34     static class B extends Exception {}
    35     static class C extends Exception {}
    36     static class C1 extends C {}
    37     static class C2 extends C {}
    39     enum ExceptionKind {
    40         A,
    41         B,
    42         C1,
    43         C2
    44     }
    46     static int caughtExceptions = 0;
    47     static int caughtRethrownExceptions = 0;
    49     static void test(ExceptionKind ekind) throws A, C1 {
    50         try {
    51             switch (ekind) {
    52                 case A : throw new A();
    53                 case B : throw new B();
    54                 case C1: throw new C1();
    55                 case C2 : throw new C2();
    56             }
    57         }
    58         catch (final C2 | B ex) {
    59             caughtExceptions++;
    60         }
    61         catch (final C | A ex) {
    62             caughtExceptions++;
    63             throw ex;
    64         }
    65     }
    67     public static void main(String[] args) {
    68         for (ExceptionKind ekind : ExceptionKind.values()) {
    69             try {
    70                 test(ekind);
    71             }
    72             catch (final C1 | A ex) {
    73                 caughtRethrownExceptions++;
    74             }
    75         }
    76         if (caughtExceptions != 4 && caughtRethrownExceptions == 2) {
    77             throw new AssertionError("Exception handler called " + caughtExceptions + "times" +
    78                                      " rethrown handler called " + caughtRethrownExceptions + "times");
    79         }
    80     }
    81 }

mercurial