Created
July 6, 2017 04:20
Revisions
-
megascus created this gist
Jul 6, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ public class CloseableTest implements AutoCloseable { public static void main(String[] args) { try (CloseableTest test = new CloseableTest()) { test.throwException();; } catch (Exception e) { System.out.println("catch exception"); System.out.println(e.getSuppressed()[0]); //close()メソッドの中で投げられた例外にcatch句でアクセスができる。 } } CloseableTest() { System.out.println("new CloseableTest"); } void throwException() throws Exception { System.out.println("throwException()"); throw new Exception(); } @Override public void close() throws Exception { System.out.println("close()"); throw new Exception("surpressed"); } }