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 */
23
24 /*
25 * @test
26 * @bug 6971877
27 * @author Joseph D. Darcy
28 * @summary Verify a primary exception suppresses all throwables
29 */
30
31 public class TwrSuppression implements AutoCloseable {
32 public static void main(String... args) throws Throwable {
33 try {
34 try (TwrSuppression r1 = new TwrSuppression(false);
35 TwrSuppression r2 = new TwrSuppression(true)) {
36 throw new RuntimeException();
37 }
38 } catch(RuntimeException e) {
39 Throwable[] suppressedExceptions = e.getSuppressedExceptions();
40 int length = suppressedExceptions.length;
41 if (length != 2)
42 throw new RuntimeException("Unexpected length " + length);
43
44 if (suppressedExceptions[0].getClass() != Error.class ||
45 suppressedExceptions[1].getClass() != Exception.class) {
46 System.err.println("Unexpected suppressed types!");
47 e.printStackTrace();
48 throw new RuntimeException(e);
49 }
50 }
51 }
52
53 private boolean throwError;
54
55 private TwrSuppression(boolean throwError) {
56 this.throwError = throwError;
57 }
58
59 @Override
|
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 */
23
24 /*
25 * @test
26 * @bug 6971877
27 * @author Joseph D. Darcy
28 * @summary Verify a primary exception suppresses all throwables
29 */
30
31 public class TwrSuppression implements AutoCloseable {
32 public static void main(String... args) throws Throwable {
33 try {
34 try (TwrSuppression r1 = new TwrSuppression(false);
35 TwrSuppression r2 = new TwrSuppression(true)) {
36 throw new RuntimeException();
37 }
38 } catch(RuntimeException e) {
39 Throwable[] suppressedExceptions = e.getSuppressed();
40 int length = suppressedExceptions.length;
41 if (length != 2)
42 throw new RuntimeException("Unexpected length " + length);
43
44 if (suppressedExceptions[0].getClass() != Error.class ||
45 suppressedExceptions[1].getClass() != Exception.class) {
46 System.err.println("Unexpected suppressed types!");
47 e.printStackTrace();
48 throw new RuntimeException(e);
49 }
50 }
51 }
52
53 private boolean throwError;
54
55 private TwrSuppression(boolean throwError) {
56 this.throwError = throwError;
57 }
58
59 @Override
|