Last active
October 25, 2015 17:07
-
-
Save aeg/84071e262b63948a747d to your computer and use it in GitHub Desktop.
AutoCloseable のテスト
This file contains 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 characters
public class CloseTest { | |
public static void main(String... args) { | |
try (TestResource rs = new TestResource()){ | |
System.out.println("try:start"); | |
throw(new Exception()); | |
} catch (Exception e) { | |
System.out.println("catch:start"); | |
e.printStackTrace(); | |
System.out.println("catch:end"); | |
} finally { | |
System.out.println("finally:"); | |
} | |
} | |
} |
This file contains 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 characters
try:start | |
close was called | |
catch:start | |
catch:end | |
finally: | |
java.lang.Exception | |
at closeable.CloseTest.main(CloseTest.java:9) | |
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) | |
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) | |
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) | |
at java.lang.reflect.Method.invoke(Method.java:601) | |
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140) |
This file contains 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 characters
public class TestResource implements AutoCloseable{ | |
@Override | |
public void close() throws Exception { | |
System.out.println("close was called"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment