Last active
December 22, 2015 07:59
-
-
Save gaul/6442289 to your computer and use it in GitHub Desktop.
Test Closer behavior with Java 6 and 7.
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
import java.io.Closeable; | |
import java.io.IOException; | |
import com.google.common.io.Closer; | |
public class CloserTest { | |
private static void testCloserJava6() throws Exception { | |
Closer closer = Closer.create(); | |
try { | |
Closeable closeable = closer.register( | |
new ThrowIOExceptionOnClose()); | |
throw new Exception("from body"); | |
} catch (Throwable t) { | |
throw closer.rethrow(t); | |
} finally { | |
closer.close(); | |
} | |
} | |
private static void testCloserJava7() throws Exception { | |
// comment for Java 6 | |
try (Closer closer = Closer.create()) { | |
closer.register(new ThrowIOExceptionOnClose()); | |
throw new Exception("from body"); | |
} | |
} | |
public static void main(String[] args) throws Exception { | |
if (args.length == 1) { | |
if (args[0].equals("java6")) { | |
testCloserJava6(); | |
} else if (args[0].equals("java7")) { | |
testCloserJava7(); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment