Created
November 1, 2018 20:58
-
-
Save trasa/5ca31019507fc9a5426ff91d6dca57e8 to your computer and use it in GitHub Desktop.
Java Try-With-Resources Example
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
@Slf4j | |
public class TWR implements Closeable() { | |
public void kaboom() throws IOException { | |
log.info("kaboom"); | |
throw new IOException("io exception here"); | |
} | |
@Override | |
public void close() { | |
log.warn("CLOSED!!"); | |
} | |
// test method | |
public static void testMe() throws IOException { | |
try(TWR c = new TWR()) { | |
c.kaboom(); | |
} | |
} | |
} | |
/* output: | |
2018-11-01 13:52:28 [main] INFO - kaboom | |
2018-11-01 13:52:28 [main] WARN - CLOSED!! | |
java.io.IOException: io exception ... | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment