Skip to content

Instantly share code, notes, and snippets.

@zinking
Created August 24, 2016 13:01
Show Gist options
  • Save zinking/4d76b4415efcdd75550bfa73de94be53 to your computer and use it in GitHub Desktop.
Save zinking/4d76b4415efcdd75550bfa73de94be53 to your computer and use it in GitHub Desktop.
useless throw POC
//In discussion of http://stackoverflow.com/questions/39118224/would-java-jit-compiler-optimise-useless-throw-statement
//awang:/tmp/ $ cat GarbageTest.java [20:57:30]
import java.io.IOException;
public class GarbageTest {
private void f() throws IOException {
throw new IOException();
}
public void garbageTest() throws IOException{
try {
f();
} finally {
System.out.println("dosomething");
}
}
public static void main(String[] args) {
GarbageTest gt = new GarbageTest();
try{
gt.garbageTest();
} catch(IOException joe) {
System.out.println("exception caught anyways");
}
}
}
/*
awang:/tmp/ $ javac GarbageTest.java [20:58:58]
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
awang:/tmp/ $ java GarbageTest [20:59:06]
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
dosomething
exception caught anyways
awang:/tmp/ $
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment