Class Exceptions
- java.lang.Object
-
- ratpack.util.Exceptions
-
public abstract class Exceptions extends java.lang.ObjectUtility methods for dealing with exceptions.
-
-
Constructor Summary
Constructors Constructor Description Exceptions()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidthrowIfError(java.lang.Throwable throwable)Throws the given throwable if it is anError, otherwise does nothing.static java.lang.ExceptiontoException(java.lang.Throwable throwable)Converts the given throwable to anExceptionif necessary.static java.lang.RuntimeExceptionuncheck(java.lang.Throwable throwable)Converts the given throwable to aRuntimeExceptionif necessary.static voiduncheck(Block action)static <T> Tuncheck(Factory<T> factory)Executes the given factory, returning its result and unchecking any exceptions it throws.static <T> voiduncheck(T input, Action<T> action)Executes the given action with the provided input argument, unchecking any exceptions it throws.static <T,U>
voiduncheck(T input1, U input2, BiAction<T,U> action)Executes the given action with the provided input arguments, unchecking any exceptions it throws.
-
-
-
Method Detail
-
uncheck
public static java.lang.RuntimeException uncheck(java.lang.Throwable throwable)
Converts the given throwable to aRuntimeExceptionif necessary.If
throwableis anError, it will be thrown.If
throwableis aRuntimeException, it will be returned unchanged.If
throwableis not aRuntimeException, a newly createdUncheckedExceptionwill 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 java.lang.Exception toException(java.lang.Throwable throwable)
Converts the given throwable to anExceptionif necessary.If
throwableis anError, it will be thrown.If
throwableis anException, it will be returned unchanged.If
throwableis not anException, a newly createdUncheckedExceptionwill 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(java.lang.Throwable throwable)
Throws the given throwable if it is anError, otherwise does nothing.- Parameters:
throwable- the throwable to throw if it is anError
-
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 actionaction- 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 argumentU- the type of the second input argument- Parameters:
input1- the first input argument to the actioninput2- the second input argument to the actionaction- the work to perform against the input
-
-