test/tools/javac/multicatch/Pos01.java

Wed, 13 Aug 2014 14:50:00 -0700

author
katleman
date
Wed, 13 Aug 2014 14:50:00 -0700
changeset 2549
0b6cc4ea670f
parent 554
9d9f26857129
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Added tag jdk8u40-b01 for changeset bf89a471779d

mcimadamore@550 1 /*
ohair@554 2 * Copyright (c) 2010, Oracle and/or its affiliates. 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 *
ohair@554 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ohair@554 20 * or visit www.oracle.com if you need additional information or have any
ohair@554 21 * 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 Pos01 {
mcimadamore@550 32
mcimadamore@550 33 static class A extends Exception {}
mcimadamore@550 34 static class B extends Exception {}
mcimadamore@550 35
mcimadamore@550 36 static int caughtExceptions = 0;
mcimadamore@550 37
mcimadamore@550 38 static void test(boolean b) {
mcimadamore@550 39 try {
mcimadamore@550 40 if (b) {
mcimadamore@550 41 throw new A();
mcimadamore@550 42 }
mcimadamore@550 43 else {
mcimadamore@550 44 throw new B();
mcimadamore@550 45 }
mcimadamore@550 46 }
mcimadamore@550 47 catch (final A | B ex) {
mcimadamore@550 48 caughtExceptions++;
mcimadamore@550 49 }
mcimadamore@550 50 }
mcimadamore@550 51
mcimadamore@550 52 public static void main(String[] args) {
mcimadamore@550 53 test(true);
mcimadamore@550 54 test(false);
mcimadamore@550 55 if (caughtExceptions != 2) {
mcimadamore@550 56 throw new AssertionError("Exception handler called " + caughtExceptions + "times");
mcimadamore@550 57 }
mcimadamore@550 58 }
mcimadamore@550 59 }

mercurial