test/tools/javac/multicatch/Pos02.java

Mon, 03 May 2010 17:12:59 -0700

author
mcimadamore
date
Mon, 03 May 2010 17:12:59 -0700
changeset 550
a6f2911a7c55
child 554
9d9f26857129
permissions
-rw-r--r--

6943289: Project Coin: Improved Exception Handling for Java (aka 'multicatch')
Reviewed-by: jjg, darcy

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

mercurial