test/tools/javac/TryWithResources/TwrFlow.java

Wed, 27 Apr 2016 01:34:52 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:34:52 +0800
changeset 0
959103a6100f
child 2525
2eb010b6cb22
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/langtools/
changeset: 2573:53ca196be1ae
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * @test /nodynamiccopyright/
aoqi@0 3 * @bug 6911256 6964740 7013420
aoqi@0 4 * @author Joseph D. Darcy
aoqi@0 5 * @summary Test exception analysis of try-with-resources blocks
aoqi@0 6 * @compile/fail/ref=TwrFlow.out -XDrawDiagnostics TwrFlow.java
aoqi@0 7 */
aoqi@0 8
aoqi@0 9 import java.io.IOException;
aoqi@0 10 public class TwrFlow implements AutoCloseable {
aoqi@0 11 public static void main(String... args) {
aoqi@0 12 try(TwrFlow twrFlow = new TwrFlow()) {
aoqi@0 13 System.out.println(twrFlow.toString());
aoqi@0 14 } catch (IOException ioe) { // Not reachable
aoqi@0 15 throw new AssertionError("Shouldn't reach here", ioe);
aoqi@0 16 }
aoqi@0 17 // CustomCloseException should be caught or added to throws clause
aoqi@0 18 }
aoqi@0 19
aoqi@0 20 /*
aoqi@0 21 * A close method, but the class is <em>not</em> Closeable or
aoqi@0 22 * AutoCloseable.
aoqi@0 23 */
aoqi@0 24 public void close() throws CustomCloseException {
aoqi@0 25 throw new CustomCloseException();
aoqi@0 26 }
aoqi@0 27 }
aoqi@0 28
aoqi@0 29 class CustomCloseException extends Exception {}

mercurial