Making a control API swallow an exception...

Neal Gafter neal at gafter.com
Sun May 4 14:41:22 PDT 2008


FYI: I've initialzed the closures mercurial forest from the tl forest.
 None of my changes are included yet.

I'm adding the following to my set of unit tests, so it will be
included when I've completed pushing the closures changes.  I've
pushed a binary prototype that properly handles this case.

/*
 * @test
  * @summary Check that APIs can be defined to swallow exceptions
 * @author gafter
 *
  * @clean Swallow
 * @compile -source 7 Swallow.java
 * @run main Swallow
  */

import java.io.*;

public class Swallow {
    static <throws X> void swallow1({ ==> void throws X, IOException}
block) throws X {
        try {
            block.invoke();
        } catch (IOException ex) {
        }
    }
    static <throws X> void swallow2({ ==> void throws IOException, X}
block) throws X {
        try {
            block.invoke();
        } catch (IOException ex) {
        }
     }
    public static void main(String[] args) {
        java.io.Closeable c = { => throw new IOException(); };
        swallow1() { c.close(); }
        swallow2() { c.close(); }
    }
}



More information about the closures-dev mailing list