test/tools/javac/TryWithResources/TwrFlow.java

changeset 0
959103a6100f
child 2525
2eb010b6cb22
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/TryWithResources/TwrFlow.java	Wed Apr 27 01:34:52 2016 +0800
     1.3 @@ -0,0 +1,29 @@
     1.4 +/*
     1.5 + * @test  /nodynamiccopyright/
     1.6 + * @bug 6911256 6964740 7013420
     1.7 + * @author Joseph D. Darcy
     1.8 + * @summary Test exception analysis of try-with-resources blocks
     1.9 + * @compile/fail/ref=TwrFlow.out -XDrawDiagnostics TwrFlow.java
    1.10 + */
    1.11 +
    1.12 +import java.io.IOException;
    1.13 +public class TwrFlow implements AutoCloseable {
    1.14 +    public static void main(String... args) {
    1.15 +        try(TwrFlow twrFlow = new TwrFlow()) {
    1.16 +            System.out.println(twrFlow.toString());
    1.17 +        } catch (IOException ioe) { // Not reachable
    1.18 +            throw new AssertionError("Shouldn't reach here", ioe);
    1.19 +        }
    1.20 +        // CustomCloseException should be caught or added to throws clause
    1.21 +    }
    1.22 +
    1.23 +    /*
    1.24 +     * A close method, but the class is <em>not</em> Closeable or
    1.25 +     * AutoCloseable.
    1.26 +     */
    1.27 +    public void close() throws CustomCloseException {
    1.28 +        throw new CustomCloseException();
    1.29 +    }
    1.30 +}
    1.31 +
    1.32 +class CustomCloseException extends Exception {}

mercurial