Archive for December, 2011

Return in finally skips the catch!

4 December 2011 Leave a comment

I was writing a JUnit Rule, when I realized that my test failures weren’t being passed through to the JUnit framework.

Here’s what my code looked like:

public Statement apply(final Statement base, FrameworkMethod method, Object target) {
  return new Statement() {
    public void evaluate() throws Throwable {
      try {
      catch (Throwable t) {
        throw t;
      finally {
        boolean something = false;
        // check something
        if( something ) {
        // do what I should otherwise do

Bizarrely (or not), that Throwable was not being thrown. After trying some different approaches, I realized that the return out of the finally was the cause.

Categories: Other