Sneaky throw

The latest issue of our magazine Jayview is out with brand new look and feel. My contribution was a cool piece of code that gets rid of those annoying exceptions. However, during layouting the link to the source disappeared. Credit should of course go to Reinier Zwitserloot and his mail on Java Posse.

public class Sneak {
    public static RuntimeException sneakyThrow(Throwable t) {
        if ( t == null ) throw new NullPointerException("t");
        Sneak.<RuntimeException>sneakyThrow0(t);
        return null;
    }

    @SuppressWarnings("unchecked")
    private static <T extends Throwable> void sneakyThrow0(Throwable t) throws T {
        throw (T)t;
    }
}

This Post Has 2 Comments

  1. anonym

    the link to jayview magazine is brocken. Where can I find the previous issues of this fine magazine, thanks!

Leave a Reply