public final class Rethrower extends Object
| 限定符和类型 | 方法和说明 |
|---|---|
static void |
rethrowIfUnrecoverable(Throwable exception)
Rethrow the supplied
exception if it is
unrecoverable. |
static <T extends Throwable> |
throwAs(Throwable t)
Rethrows
t (identical object). |
static RuntimeException |
throwAsUncheckedException(Throwable t)
Throw the supplied
Throwable, masked as an
unchecked exception. |
public static void rethrowIfUnrecoverable(Throwable exception)
exception if it is
unrecoverable.
If the supplied exception is not unrecoverable, this
method does nothing.
public static RuntimeException throwAsUncheckedException(Throwable t)
Throwable, masked as an
unchecked exception.
The supplied Throwable will 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.
This method should be used sparingly.
t - the Throwable to throw as an unchecked exception;
never nullthrow statementCopyright © 2021. All rights reserved.