Package ratpack.func

Class Exceptions


  • public abstract class Exceptions
    extends Object
    Utility methods for dealing with exceptions.
    • Constructor Detail

      • Exceptions

        public Exceptions()
    • Method Detail

      • uncheck

        public static RuntimeException uncheck​(Throwable throwable)
        Converts the given throwable to a RuntimeException if necessary.

        If throwable is an Error, it will be thrown.

        If throwable is a RuntimeException, it will be returned unchanged.

        If throwable is not a RuntimeException, a newly created UncheckedException will be returned with the original throwable as the cause and with no message.

        Parameters:
        throwable - the throwable to ensure is a runtime exception
        Returns:
        a runtime throwable
      • toException

        public static Exception toException​(Throwable throwable)
        Converts the given throwable to an Exception if necessary.

        If throwable is an Error, it will be thrown.

        If throwable is an Exception, it will be returned unchanged.

        If throwable is not an Exception, a newly created UncheckedException will be returned with the original throwable as the cause and with no message.

        Parameters:
        throwable - the throwable to ensure is an exception
        Returns:
        a runtime throwable
      • throwIfError

        public static void throwIfError​(Throwable throwable)
        Throws the given throwable if it is an Error, otherwise does nothing.
        Parameters:
        throwable - the throwable to throw if it is an Error
      • uncheck

        public static <T> T uncheck​(Factory<T> factory)
        Executes the given factory, returning its result and unchecking any exceptions it throws.

        If the factory throws an exception, it will be thrown via uncheck(Throwable).

        Type Parameters:
        T - the type of value produced
        Parameters:
        factory - a value producer
        Returns:
        the value produced by the given factory
      • uncheck

        public static void uncheck​(Block action)
      • uncheck

        public static <T> void uncheck​(T input,
                                       Action<T> action)
        Executes the given action with the provided input argument, unchecking any exceptions it throws.

        If the factory throws an exception, it will be thrown via uncheck(Throwable).

        Type Parameters:
        T - the type of the input argument
        Parameters:
        input - the input argument to the action
        action - the work to perform against the input
      • uncheck

        public static <T,​U> void uncheck​(T input1,
                                               U input2,
                                               BiAction<T,​U> action)
        Executes the given action with the provided input arguments, unchecking any exceptions it throws.

        If the factory throws an exception, it will be thrown via uncheck(Throwable).

        Type Parameters:
        T - the type of the first input argument
        U - the type of the second input argument
        Parameters:
        input1 - the first input argument to the action
        input2 - the second input argument to the action
        action - the work to perform against the input