Class SneakyThrow


  • public class SneakyThrow
    extends Object
    An utility class which makes possible to throw any exception as a RuntimeException. It means to throw checked exception (subtype of Throwable or Exception) as un-checked exception. This considers the Java 8 inference rule that states that a throws E is inferred as RuntimeException.
    • Method Detail

      • sneakyThrow

        public static <E extends Throwable> void sneakyThrow​(Throwable e)
                                                      throws E extends Throwable
        This method can be used in throw statement such as: throw sneakyThrow(exception);.
        Throws:
        E extends Throwable