public abstract class Exceptions
extends java.lang.Object
| Constructor and Description |
|---|
Exceptions() |
| Modifier and Type | Method and Description |
|---|---|
static void |
throwIfError(java.lang.Throwable throwable)
Throws the given throwable if it is an
Error, otherwise does nothing. |
static java.lang.Exception |
toException(java.lang.Throwable throwable)
Converts the given throwable to an
Exception if necessary. |
static void |
uncheck(Block action) |
static <T> T |
uncheck(Factory<T> factory)
Executes the given factory, returning its result and unchecking any exceptions it throws.
|
static <T> void |
uncheck(T input,
Action<T> action)
Executes the given action with the provided input argument, unchecking any exceptions it throws.
|
static java.lang.RuntimeException |
uncheck(java.lang.Throwable throwable)
Converts the given throwable to a
RuntimeException if necessary. |
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.
|
public static java.lang.RuntimeException uncheck(java.lang.Throwable throwable)
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.
throwable - the throwable to ensure is a runtime exceptionpublic static java.lang.Exception toException(java.lang.Throwable throwable)
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.
throwable - the throwable to ensure is an exceptionpublic static void throwIfError(java.lang.Throwable throwable)
Error, otherwise does nothing.throwable - the throwable to throw if it is an Errorpublic static <T> T uncheck(Factory<T> factory)
If the factory throws an exception, it will be thrown via uncheck(Throwable).
T - the type of value producedfactory - a value producerpublic static void uncheck(Block action)
public static <T> void uncheck(T input,
Action<T> action)
If the factory throws an exception, it will be thrown via uncheck(Throwable).
T - the type of the input argumentinput - the input argument to the actionaction - the work to perform against the inputpublic static <T,U> void uncheck(T input1,
U input2,
BiAction<T,U> action)
If the factory throws an exception, it will be thrown via uncheck(Throwable).
T - the type of the first input argumentU - the type of the second input argumentinput1 - the first input argument to the actioninput2 - the second input argument to the actionaction - the work to perform against the input