Class SneakyThrow


  • public class SneakyThrow
    extends java.lang.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 Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static <E extends java.lang.Throwable>
      void
      sneakyThrow​(java.lang.Throwable e)
      This method can be used in throw statement such as: throw sneakyThrow(exception);.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • sneakyThrow

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