public class Throwables extends Object
| 限定符和类型 | 方法和说明 |
|---|---|
static Throwable |
getRootCause(Throwable ex) |
static String |
getStackTraceAsString(Throwable throwable) |
static <I,O> O |
ignoreExceptions(org.slf4j.Logger logger,
O valueIfError,
List<Class<Throwable>> throwables,
ThrowableFunction<I,O> func,
I input) |
static <I1,I2,O> O |
ignoreExceptions(org.slf4j.Logger logger,
O valueIfError,
List<Class<Throwable>> throwables,
ThrowableFunction2<I1,I2,O> func,
I1 input1,
I2 input2) |
static <I,O> O |
ignoreThrowable(org.slf4j.Logger logger,
O valueIfError,
ThrowableFunction<I,O> func,
I input) |
static <I1,I2,O> O |
ignoreThrowable(org.slf4j.Logger logger,
O valueIfError,
ThrowableFunction2<I1,I2,O> func,
I1 input1,
I2 input2) |
static List<StackTraceElement> |
lazyStackTrace(Throwable throwable)
Returns the stack trace of
throwable, possibly providing slower iteration over the full
trace but faster iteration over parts of the trace. |
static boolean |
lazyStackTraceIsLazy()
Returns whether
lazyStackTrace(java.lang.Throwable) will use the special implementation described in its
documentation. |
static void |
log(org.slf4j.Logger logger,
org.slf4j.event.Level level,
String message,
Throwable ex) |
static void |
log(Throwable ex) |
static String |
stringify(Throwable t) |
static void |
throwAsRuntimeException(Throwable ex) |
static Throwable |
throwIfError(Throwable ex) |
static Throwable |
throwIfIOException(Throwable ex) |
static Throwable |
throwIfRuntimeException(Throwable ex) |
static Throwable |
throwRootCauseIfIOException(Throwable ex)
step1 : get root cause
step2 : throwIfIOException(root cause)
|
static RuntimeException |
wrapAsRuntimeException(Throwable ex) |
public static Throwable throwIfIOException(Throwable ex) throws IOException
IOExceptionpublic static RuntimeException wrapAsRuntimeException(Throwable ex)
public static void throwAsRuntimeException(Throwable ex)
public static Throwable throwRootCauseIfIOException(Throwable ex) throws IOException
IOExceptionpublic static void log(@Nullable org.slf4j.Logger logger, @Nullable org.slf4j.event.Level level, @Nullable String message, @NonNull Throwable ex)
public static List<StackTraceElement> lazyStackTrace(Throwable throwable)
throwable, possibly providing slower iteration over the full
trace but faster iteration over parts of the trace. Here, "slower" and "faster" are defined in
comparison to the normal way to access the stack trace, throwable.getStackTrace(). Note, however, that this method's special implementation is not
available for all platforms and configurations. If that implementation is unavailable, this
method falls back to getStackTrace. Callers that require the special implementation can
check its availability with lazyStackTraceIsLazy().
The expected (but not guaranteed) performance of the special implementation differs from
getStackTrace in one main way: The lazyStackTrace call itself returns quickly
by delaying the per-stack-frame work until each element is accessed. Roughly speaking:
getStackTrace takes stackSize time to return but then negligible time to
retrieve each element of the returned list.
lazyStackTrace takes negligible time to return but then 1/stackSize time
to retrieve each element of the returned list (probably slightly more than 1/stackSize).
Note: The special implementation does not respect calls to throwable.setStackTrace. Instead, it always reflects the original stack trace from the
exception's creation.
public static boolean lazyStackTraceIsLazy()
lazyStackTrace(java.lang.Throwable) will use the special implementation described in its
documentation.public static <I,O> O ignoreThrowable(@Nullable org.slf4j.Logger logger, @Nullable O valueIfError, @NonNull ThrowableFunction<I,O> func, @Nullable I input)
public static <I1,I2,O> O ignoreThrowable(@Nullable org.slf4j.Logger logger, @Nullable O valueIfError, @NonNull ThrowableFunction2<I1,I2,O> func, @Nullable I1 input1, @Nullable I2 input2)
public static <I,O> O ignoreExceptions(@Nullable org.slf4j.Logger logger, @Nullable O valueIfError, @NonNull List<Class<Throwable>> throwables, @NonNull ThrowableFunction<I,O> func, @Nullable I input)
public static <I1,I2,O> O ignoreExceptions(@Nullable org.slf4j.Logger logger, @Nullable O valueIfError, @NonNull List<Class<Throwable>> throwables, @NonNull ThrowableFunction2<I1,I2,O> func, @Nullable I1 input1, @Nullable I2 input2)
Copyright © 2020. All rights reserved.