Package cn.sliew.sakura.common.exception
Enum Rethrower
- java.lang.Object
-
- java.lang.Enum<Rethrower>
-
- cn.sliew.sakura.common.exception.Rethrower
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceRethrower.Procedure
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidrethrowIfUnrecoverable(java.lang.Throwable exception)Rethrow the suppliedexceptionif it is unrecoverable.static voidswallow(Rethrower.Procedure procedure)static <T extends java.lang.Throwable>
voidthrowAs(java.lang.Throwable t)Rethrowst(identical object).static java.lang.RuntimeExceptionthrowAsUncheckedException(java.lang.Throwable t)Throw the suppliedThrowable, masked as an unchecked exception.static voidtoIllegalArgument(Rethrower.Procedure voidCallable)static voidtoIllegalState(Rethrower.Procedure voidCallable)static voidtoRuntime(Rethrower.Procedure voidCallable)Catch a checked exception and rethrow as aRuntimeException.static <T> TtoRuntime(java.util.concurrent.Callable<T> callable)Catch a checked exception and rethrow as aRuntimeExceptionstatic RethrowervalueOf(java.lang.String name)Returns the enum constant of this type with the specified name.static Rethrower[]values()Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Method Detail
-
values
public static Rethrower[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (Rethrower c : Rethrower.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static Rethrower valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
java.lang.IllegalArgumentException- if this enum type has no constant with the specified namejava.lang.NullPointerException- if the argument is null
-
rethrowIfUnrecoverable
public static void rethrowIfUnrecoverable(java.lang.Throwable exception)
Rethrow the suppliedexceptionif it is unrecoverable.If the supplied
exceptionis not unrecoverable, this method does nothing.
-
throwAsUncheckedException
public static java.lang.RuntimeException throwAsUncheckedException(java.lang.Throwable t)
Throw the suppliedThrowable, masked as an unchecked exception.The supplied
Throwablewill not be wrapped. Rather, it will be thrown as is using an exploit of the Java language that relies on a combination of generics and type erasure to trick the Java compiler into believing that the thrown exception is an unchecked exception even if it is a checked exception.Warning
This method should be used sparingly.
- Parameters:
t- theThrowableto throw as an unchecked exception; nevernull- Returns:
- this method always throws an exception and therefore never
returns anything; the return type is merely present to allow this
method to be supplied as the operand in a
throwstatement
-
throwAs
public static <T extends java.lang.Throwable> void throwAs(java.lang.Throwable t) throws T extends java.lang.ThrowableRethrowst(identical object).- Throws:
T extends java.lang.Throwable
-
toRuntime
public static <T> T toRuntime(java.util.concurrent.Callable<T> callable)
Catch a checked exception and rethrow as aRuntimeException- Type Parameters:
T- return type of the function.- Parameters:
callable- function that throws a checked exception.- Returns:
- object that the function returns.
-
toRuntime
public static void toRuntime(Rethrower.Procedure voidCallable)
Catch a checked exception and rethrow as aRuntimeException.- Parameters:
voidCallable- function that throws a checked exception.
-
toIllegalState
public static void toIllegalState(Rethrower.Procedure voidCallable)
-
toIllegalArgument
public static void toIllegalArgument(Rethrower.Procedure voidCallable)
-
swallow
public static void swallow(Rethrower.Procedure procedure)
-
-