mcimadamore@550: /* mcimadamore@550: * Copyright 2010 Sun Microsystems, Inc. All Rights Reserved. mcimadamore@550: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. mcimadamore@550: * mcimadamore@550: * This code is free software; you can redistribute it and/or modify it mcimadamore@550: * under the terms of the GNU General Public License version 2 only, as mcimadamore@550: * published by the Free Software Foundation. mcimadamore@550: * mcimadamore@550: * This code is distributed in the hope that it will be useful, but WITHOUT mcimadamore@550: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or mcimadamore@550: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License mcimadamore@550: * version 2 for more details (a copy is included in the LICENSE file that mcimadamore@550: * accompanied this code). mcimadamore@550: * mcimadamore@550: * You should have received a copy of the GNU General Public License version mcimadamore@550: * 2 along with this work; if not, write to the Free Software Foundation, mcimadamore@550: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. mcimadamore@550: * mcimadamore@550: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, mcimadamore@550: * CA 95054 USA or visit www.sun.com if you need additional information or mcimadamore@550: * have any questions. mcimadamore@550: */ mcimadamore@550: mcimadamore@550: /* mcimadamore@550: * @test mcimadamore@550: * @bug 6943289 mcimadamore@550: * @summary Project Coin: Improved Exception Handling for Java (aka 'multicatch') mcimadamore@550: * mcimadamore@550: */ mcimadamore@550: mcimadamore@550: public class Pos02 { mcimadamore@550: mcimadamore@550: static class A extends Exception {} mcimadamore@550: static class B extends Exception {} mcimadamore@550: static class C extends Exception {} mcimadamore@550: static class C1 extends C {} mcimadamore@550: static class C2 extends C {} mcimadamore@550: mcimadamore@550: enum ExceptionKind { mcimadamore@550: A, mcimadamore@550: B, mcimadamore@550: C1, mcimadamore@550: C2 mcimadamore@550: } mcimadamore@550: mcimadamore@550: static int caughtExceptions = 0; mcimadamore@550: static int caughtRethrownExceptions = 0; mcimadamore@550: mcimadamore@550: static void test(ExceptionKind ekind) throws A, C1 { mcimadamore@550: try { mcimadamore@550: switch (ekind) { mcimadamore@550: case A : throw new A(); mcimadamore@550: case B : throw new B(); mcimadamore@550: case C1: throw new C1(); mcimadamore@550: case C2 : throw new C2(); mcimadamore@550: } mcimadamore@550: } mcimadamore@550: catch (final C2 | B ex) { mcimadamore@550: caughtExceptions++; mcimadamore@550: } mcimadamore@550: catch (final C | A ex) { mcimadamore@550: caughtExceptions++; mcimadamore@550: throw ex; mcimadamore@550: } mcimadamore@550: } mcimadamore@550: mcimadamore@550: public static void main(String[] args) { mcimadamore@550: for (ExceptionKind ekind : ExceptionKind.values()) { mcimadamore@550: try { mcimadamore@550: test(ekind); mcimadamore@550: } mcimadamore@550: catch (final C1 | A ex) { mcimadamore@550: caughtRethrownExceptions++; mcimadamore@550: } mcimadamore@550: } mcimadamore@550: if (caughtExceptions != 4 && caughtRethrownExceptions == 2) { mcimadamore@550: throw new AssertionError("Exception handler called " + caughtExceptions + "times" + mcimadamore@550: " rethrown handler called " + caughtRethrownExceptions + "times"); mcimadamore@550: } mcimadamore@550: } mcimadamore@550: }