July 8, 2009

I/O Fundamentals

May 16, 2009

Java Traps: return in a finally clause

The following code does not throw RuntimeException -- it is lost....


public class MainApp {
public static void main(String[] args) {
try {
produceRuntimeException();
System.out.println("yikes!!!");
} catch (Exception ex) {
System.err.println("Got it!" );
}

}

private static void produceRuntimeException() {
try {
throw new RuntimeException();
} finally {
return;
}
}
}

January 5, 2009

Hello, world

private Object theGodKillsKittenEveryTimeYouUseThisVariable;
...
public Object getTheGodKillsKittenEveryTimeYouUseThisVariable(){
Object killedKitten=theGodKillsKittenEveryTimeYouUseThisVariable;
return killedKitten;
}