@ParametersAreNonnullByDefault public final class Throwables extends Object
Modifier and Type | Class and Description |
---|---|
static class |
Throwables.PackageDetail
enum describing the PackageDetail level to be logged in the stack trace.
|
static class |
Throwables.TrimmedException |
Modifier and Type | Field and Description |
---|---|
static String |
CAUSE_CAPTION
Caption for labeling causative exception stack traces
|
static int |
MAX_THROWABLE_CHAIN |
static String |
SUPPRESSED_CAPTION
Caption for labeling suppressed exception stack traces
|
Modifier and Type | Method and Description |
---|---|
static <T extends Throwable> |
chain(T t,
Throwable newRootCause)
This method will clone the exception t and will set a new root cause.
|
static <T extends Throwable> |
chain(T t,
Throwable newRootCause,
int maxChained) |
static int |
commonFrames(StackTraceElement[] trace,
StackTraceElement[] enclosingTrace) |
static boolean |
contains(Throwable t,
Predicate<Throwable> predicate)
checks in the throwable + children (both causal and suppressed) contain a throwable that
respects the Predicate.
|
static boolean |
containsNonRecoverable(Throwable t)
Does this Throwable contain a JVM non-recoverable exception.
|
static <T extends Throwable> |
first(Throwable t,
Class<T> clasz)
return first Exception in the causal chain Assignable to clasz.
|
static Throwable |
first(Throwable t,
Predicate<Throwable> predicate)
Returns the first Throwable that matches the predicate in the causal and suppressed chain,
the suppressed chain includes the supression mechanism included in SQLException.
|
static Throwable |
firstCause(Throwable throwable,
Predicate<Throwable> predicate)
Returns first Throwable in the causality chain that is matching the provided predicate.
|
static Predicate<Throwable> |
getIsRetryablePredicate() |
static Predicate<Throwable> |
getNonRecoverablePredicate() |
static int |
getNrRecursiveSuppressedExceptions(Throwable t) |
static int |
getNrSuppressedExceptions(Throwable t) |
static Throwable[] |
getSuppressed(Throwable t)
Utility to get suppressed exceptions.
|
static boolean |
isNonRecoverable(Throwable t)
Is this Throwable a JVM non-recoverable exception.
|
static boolean |
isRetryable(Exception value)
figure out if a Exception is retry-able or not.
|
static Throwable |
removeOldestSuppressed(Throwable t) |
static Throwable |
removeOldestSuppressedRecursive(Throwable t) |
static void |
setIsRetryablePredicate(Predicate<Throwable> isRetryablePredicate) |
static void |
setNonRecoverablePredicate(Predicate<Throwable> predicate)
Overwrite the default non-recoverable predicate.
|
static <T extends Throwable> |
suppress(T t,
Throwable suppressed)
Functionality similar for java 1.7 Throwable.addSuppressed.
|
static <T extends Throwable> |
suppress(T t,
Throwable suppressed,
int maxSuppressed) |
static void |
throwException(Exception ex) |
static String |
toString(Throwable t) |
static String |
toString(Throwable t,
Throwables.PackageDetail detail) |
static String |
toString(Throwable t,
Throwables.PackageDetail detail,
boolean abbreviatedTraceElement) |
static StringBuilder |
toStringBuilder(Throwable t,
Throwables.PackageDetail detail) |
static StringBuilder |
toStringBuilder(Throwable t,
Throwables.PackageDetail detail,
boolean abbreviatedTraceElement) |
static void |
trimCausalChain(Throwable t,
int maxSize) |
static void |
writeAbreviatedClassName(String className,
Appendable writeTo) |
static void |
writeMessageString(Appendable to,
Throwable t) |
static void |
writeTo(StackTraceElement[] trace,
Appendable to,
Throwables.PackageDetail detail,
boolean abbreviatedTraceElement) |
static void |
writeTo(StackTraceElement[] trace,
Appendable to,
Throwables.PackageDetail detail,
boolean abbreviatedTraceElement,
String prefix) |
static void |
writeTo(StackTraceElement element,
StackTraceElement previous,
Appendable to,
Throwables.PackageDetail detail,
boolean abbreviatedTraceElement) |
static void |
writeTo(Throwable t,
Appendable to,
Throwables.PackageDetail detail) |
static void |
writeTo(Throwable t,
Appendable to,
Throwables.PackageDetail detail,
boolean abbreviatedTraceElement) |
static void |
writeTo(Throwable t,
Appendable to,
Throwables.PackageDetail detail,
boolean abbreviatedTraceElement,
String prefix) |
static void |
writeTo(Throwable t,
Appendable to,
Throwables.PackageDetail detail,
String prefix) |
static void |
writeTo(Throwable t,
PrintStream to,
Throwables.PackageDetail detail) |
static void |
writeTo(Throwable t,
PrintStream to,
Throwables.PackageDetail detail,
boolean abbreviatedTraceElement) |
public static final String SUPPRESSED_CAPTION
public static final String CAUSE_CAPTION
public static final int MAX_THROWABLE_CHAIN
public static boolean isRetryable(Exception value)
value
- public static void setIsRetryablePredicate(Predicate<Throwable> isRetryablePredicate)
public static int getNrSuppressedExceptions(Throwable t)
public static int getNrRecursiveSuppressedExceptions(Throwable t)
@Nullable public static Throwable removeOldestSuppressedRecursive(Throwable t)
public static <T extends Throwable> T chain(T t, Throwable newRootCause)
T
- t
- newRootCause
- public static void trimCausalChain(Throwable t, int maxSize)
@CheckReturnValue public static <T extends Throwable> T suppress(@Nonnull T t, @Nonnull Throwable suppressed)
T
- t
- suppressed
- @CheckReturnValue public static <T extends Throwable> T suppress(@Nonnull T t, @Nonnull Throwable suppressed, int maxSuppressed)
public static Throwable[] getSuppressed(Throwable t)
t
- public static void writeTo(StackTraceElement element, @Nullable StackTraceElement previous, Appendable to, Throwables.PackageDetail detail, boolean abbreviatedTraceElement) throws IOException
IOException
public static String toString(Throwable t, Throwables.PackageDetail detail)
public static String toString(Throwable t, Throwables.PackageDetail detail, boolean abbreviatedTraceElement)
public static StringBuilder toStringBuilder(Throwable t, Throwables.PackageDetail detail)
public static StringBuilder toStringBuilder(Throwable t, Throwables.PackageDetail detail, boolean abbreviatedTraceElement)
public static void writeTo(@Nonnull Throwable t, @Nonnull PrintStream to, @Nonnull Throwables.PackageDetail detail)
public static void writeTo(@Nonnull Throwable t, @Nonnull PrintStream to, @Nonnull Throwables.PackageDetail detail, boolean abbreviatedTraceElement)
public static void writeTo(Throwable t, Appendable to, Throwables.PackageDetail detail) throws IOException
IOException
public static void writeTo(Throwable t, Appendable to, Throwables.PackageDetail detail, String prefix) throws IOException
IOException
public static void writeTo(Throwable t, Appendable to, Throwables.PackageDetail detail, boolean abbreviatedTraceElement) throws IOException
IOException
public static void writeTo(Throwable t, Appendable to, Throwables.PackageDetail detail, boolean abbreviatedTraceElement, String prefix) throws IOException
IOException
public static void writeMessageString(Appendable to, Throwable t) throws IOException
IOException
public static void writeTo(StackTraceElement[] trace, Appendable to, Throwables.PackageDetail detail, boolean abbreviatedTraceElement) throws IOException
IOException
public static void writeTo(StackTraceElement[] trace, Appendable to, Throwables.PackageDetail detail, boolean abbreviatedTraceElement, String prefix) throws IOException
IOException
public static int commonFrames(StackTraceElement[] trace, StackTraceElement[] enclosingTrace)
public static boolean isNonRecoverable(@Nonnull Throwable t)
t
- public static boolean containsNonRecoverable(@Nonnull Throwable t)
t
- public static boolean contains(@Nonnull Throwable t, Predicate<Throwable> predicate)
t
- the throwablepredicate
- the predicate@Nullable @CheckReturnValue public static <T extends Throwable> T first(@Nonnull Throwable t, Class<T> clasz)
T
- t
- clasz
- @Nullable @CheckReturnValue public static Throwable first(@Nonnull Throwable t, Predicate<Throwable> predicate)
t
- the Throwablepredicate
- the Predicate@Nullable @CheckReturnValue public static Throwable firstCause(@Nonnull Throwable throwable, Predicate<Throwable> predicate)
throwable
- the Throwable to go through.predicate
- the predicate to applypublic static void setNonRecoverablePredicate(Predicate<Throwable> predicate)
predicate
- public static void writeAbreviatedClassName(String className, Appendable writeTo) throws IOException
IOException
public static void throwException(Exception ex) throws IOException, InterruptedException, ExecutionException, TimeoutException
Copyright © 2018 SPF4J. All rights reserved.