test/tools/javac/TryWithResources/TwrFlow.java

Tue, 25 Jan 2011 17:02:56 -0800

author
darcy
date
Tue, 25 Jan 2011 17:02:56 -0800
changeset 840
7f8794f9cc14
parent 609
13354e1abba7
child 2525
2eb010b6cb22
permissions
-rw-r--r--

7013420: Project Coin: remove general expression support from try-with-resources statement
Reviewed-by: mcimadamore, jjg

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

mercurial