Class Exceptions


  • @GwtCompatible
    public class Exceptions
    extends java.lang.Object
    Useful helper methods when dealing with exceptions.
    • Constructor Summary

      Constructors 
      Constructor Description
      Exceptions()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.RuntimeException sneakyThrow​(java.lang.Throwable t)
      Throws the given exception and sneaks it through any compiler checks.
      • Methods inherited from class java.lang.Object

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

      • Exceptions

        public Exceptions()
    • Method Detail

      • sneakyThrow

        public static java.lang.RuntimeException sneakyThrow​(java.lang.Throwable t)
        Throws the given exception and sneaks it through any compiler checks. This allows to throw checked exceptions without the need to declare it. Clients should use the following idiom to trick static analysis and dead code checks:
         throw sneakyThrow(new CheckedException("Catch me if you can ;-)")).
         
        This method is heavily inspired by project Lombok.
        Parameters:
        t - the throwable that should be sneaked through compiler checks. May not be null.
        Returns:
        never returns anything since t is always thrown.
        Throws:
        java.lang.NullPointerException - if t is null.