public class ThrowableTools
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static java.util.Map |
DEFAULT_KNOWN_EXCEPTION_WRAPPERS |
| Modifier and Type | Method and Description |
|---|---|
static void |
dumpJVMStack()
Prints a filtered thread dump of all active threads in the JVM to
System.err. |
static void |
dumpJVMStack(java.io.PrintStream ps)
Prints a filtered thread dump of all active threads in the JVM to the specified stream.
|
static void |
dumpStack()
Prints a filtered stack dump of the calling thread to
System.err. |
static void |
dumpStack(java.lang.String msg)
Prints a filtered stack dump of the calling thread with an optional prefix message to
System.err. |
static void |
dumpStack(java.lang.String msg,
java.io.PrintStream ps)
Prints a filtered stack dump of the calling thread to the specified stream.
|
static boolean |
equals(java.lang.Throwable throwable1,
java.lang.Throwable throwable2)
Evaluates deep equality between two throwable hierarchies.
|
static void |
filterAndDumpStackTrace(java.lang.String str)
Reads a stacktrace given as
String and dumps it to STDOUT in
filtered form. |
static java.lang.StackTraceElement[] |
filterStackTrace(java.lang.StackTraceElement[] stack)
Returns a new array containing only stack trace elements that match standard filter criteria.
|
static java.lang.StackTraceElement[] |
filterStackTrace(java.lang.StackTraceElement[] stack,
StackTraceFilter[] filters)
Returns a new array containing only stack trace elements that pass all specified filter rules.
|
static java.lang.Throwable |
filterStackTrace(java.lang.Throwable t)
Filters the stack trace of a throwable and all its underlying causes using default filters.
|
static java.lang.Throwable |
filterStackTrace(java.lang.Throwable t,
StackTraceFilter[] filters)
Filters the stack trace of a throwable and all its underlying causes using explicit filter rules.
|
static java.lang.Throwable[] |
getAllCauses(java.lang.Throwable t)
Collects the full causal chain of a throwable starting from the given root.
|
static java.lang.Throwable |
getCause(java.lang.Throwable t)
Resolves the underlying cause of an exception.
|
static java.lang.String |
getCauseMethod(java.lang.Throwable t)
Returns the method name needed to get the 'cause' of the given t.
|
static java.lang.Throwable |
getCauseOfClass(java.lang.Class clazz,
java.lang.Throwable t)
Deprecated.
Replaced by
getCauseOfClass(Throwable, Class) to follow standard (subject, predicate) parameter ordering. |
static java.lang.Throwable |
getCauseOfClass(java.lang.Throwable t,
java.lang.Class clazz)
Traverses the exception cause chain to locate the first instance assignable to the specified class.
|
static java.lang.Throwable |
getDeepestCauseOfClass(java.lang.Class clazz,
java.lang.Throwable t)
Deprecated.
Replaced by
getDeepestCauseOfClass(Throwable, Class) to follow standard (subject, predicate) parameter ordering. |
static java.lang.Throwable |
getDeepestCauseOfClass(java.lang.Throwable t,
java.lang.Class clazz)
Traverses the full exception cause chain to locate the innermost instance assignable to the specified class.
|
static java.lang.String |
getErrortext(java.lang.Exception ex)
Formats an exception into a persistent diagnostic text block containing its class, message, and trace.
|
static java.lang.String |
getErrortext(java.lang.Exception ex,
java.lang.String msg)
Formats an exception into a persistent diagnostic text block preceded by a custom context message.
|
static java.lang.Throwable |
getRootCause(java.lang.Throwable t)
Traverses the exception cause chain to locate the ultimate root cause.
|
static java.lang.String |
getStackTraceAsString(java.lang.Thread t)
Formats the full, unfiltered stack trace of a thread as a string.
|
static java.lang.String |
getStackTraceAsString(java.lang.Thread t,
boolean filtered)
Formats the current stack trace of a thread as a string, optionally applying standard filters.
|
static java.lang.String |
getStackTraceAsString(java.lang.Thread t,
OutputConfiguration outputConfig)
Formats the current stack trace of a thread as a string using the specified output configuration.
|
static java.lang.String |
getStackTraceAsString(java.lang.Throwable t)
Formats the full stack trace of a throwable as an unfiltered string.
|
static java.lang.String |
getStackTraceAsString(java.lang.Throwable t,
boolean filtered)
Formats the stack trace of a throwable as a string, optionally filtering out standard runtime noise.
|
static java.lang.String |
getStackTraceAsString(java.lang.Throwable t,
OutputConfiguration outputConfig)
Formats the stack trace of a throwable as a string using the specified output configuration.
|
static java.lang.StackTraceElement |
getStackTraceElement(java.lang.Throwable t,
java.lang.String declaringClass,
java.lang.String methodName)
Locates the first stack trace element within a throwable matching the specified class and method.
|
static java.lang.StackTraceElement |
getStackTraceElement(java.lang.Throwable t,
java.lang.String declaringClass,
java.lang.String methodName,
java.lang.String fileName)
Locates the first stack trace element within a throwable matching the specified class, method, and optional filename.
|
static java.lang.String |
getUserRelevantMessage(java.lang.Throwable t)
Resolves a user-facing message from a throwable hierarchy, prioritizing runtime exceptions.
|
static java.lang.String |
getUserRelevantMessage(java.lang.Throwable t,
java.lang.Class<? extends java.lang.Throwable> preferType)
Resolves a user-facing message from a throwable hierarchy using a prioritized resolution chain.
|
static boolean |
hasCauseOfClass(java.lang.Class clazz,
java.lang.Throwable t)
Deprecated.
Replaced by
hasCauseOfClass(Throwable, Class) to follow standard (subject, predicate) parameter ordering. |
static boolean |
hasCauseOfClass(java.lang.Throwable t,
java.lang.Class clazz)
Checks whether the causal chain contains an exception assignable to the specified class.
|
static boolean |
isKnownWrapperException(java.lang.Throwable t)
Determines whether the specified throwable is a standard reflection or concurrency wrapper.
|
static void |
printStackTrace(java.lang.StackTraceElement[] stackTraceEls,
java.io.PrintWriter pw)
Prints raw stack trace elements to the target writer without filtering.
|
static void |
printStackTrace(java.lang.StackTraceElement[] stackTraceEls,
java.io.PrintWriter pw,
OutputConfiguration outputConfig)
Prints raw stack trace elements to the target writer using the specified output configuration.
|
static void |
printStackTrace(java.lang.StackTraceElement[] stackTraceEls,
java.io.PrintWriter pw,
OutputConfiguration outputConfig,
int upToFrame)
Prints raw stack trace elements to the target writer up to the designated frame index limit.
|
static void |
printStackTrace(java.lang.StackTraceElement[] stackTraceEls,
java.io.PrintWriter pw,
OutputConfiguration outputConfig,
int upToFrame,
int fromFrame)
Prints a slice of raw stack trace elements to the target writer.
|
static void |
printStackTrace(java.lang.Throwable t,
boolean filtered)
Prints the stack trace of a throwable to
System.err, optionally applying default filtering. |
static void |
printStackTrace(java.lang.Throwable t,
java.io.PrintStream ps)
Prints the complete, unfiltered stack trace of a throwable to the target stream.
|
static void |
printStackTrace(java.lang.Throwable t,
java.io.PrintStream ps,
boolean filtered)
Prints the stack trace of a throwable to the target stream, optionally applying default filtering.
|
static void |
printStackTrace(java.lang.Throwable t,
java.io.PrintStream ps,
OutputConfiguration outputConfig)
Prints the stack trace of a throwable to the target stream using the specified output configuration.
|
static void |
printStackTrace(java.lang.Throwable t,
java.io.PrintStream ps,
OutputConfiguration outputConfig,
int upToFrame)
Prints the stack trace of a throwable to the target stream up to the designated frame index limit.
|
static void |
printStackTrace(java.lang.Throwable t,
java.io.PrintStream ps,
OutputConfiguration outputConfig,
int upToFrame,
int fromFrame)
Prints a slice of the stack trace of a throwable to the target stream.
|
static void |
printStackTrace(java.lang.Throwable t,
java.io.PrintWriter pw)
Prints the complete, unfiltered stack trace of a throwable to the target writer.
|
static void |
printStackTrace(java.lang.Throwable t,
java.io.PrintWriter pw,
OutputConfiguration outputConfig)
Prints the stack trace of a throwable to the target writer using the specified output configuration.
|
static void |
printStackTrace(java.lang.Throwable t,
java.io.PrintWriter pw,
OutputConfiguration outputConfig,
int upToFrame)
Prints the stack trace of a throwable to the target writer up to the designated frame index limit.
|
static void |
printStackTrace(java.lang.Throwable t,
java.io.PrintWriter pw,
OutputConfiguration outputConfig,
int upToFrame,
int fromFrame)
Prints a slice of the stack trace of a throwable to the target writer, cascading down the causal chain.
|
static void |
printStackTraceAsCause(java.lang.String cm,
java.lang.Throwable t,
java.io.PrintWriter pw,
java.lang.StackTraceElement[] causedTrace,
OutputConfiguration outputConfig)
Prints a nested causal exception trace, trimming frames shared with the enclosing caused trace.
|
public static final java.util.Map DEFAULT_KNOWN_EXCEPTION_WRAPPERS
public static java.lang.Throwable getCause(java.lang.Throwable t)
Prefers Throwable.getCause(). If null, inspects engine-specific wrapper
accessors defined in CAUSE_METHODS (such as BeanShell's TargetError).
t - the throwable to inspectpublic static java.lang.Throwable[] getAllCauses(java.lang.Throwable t)
t - top-level throwable to inspectt is nullpublic static java.lang.String getCauseMethod(java.lang.Throwable t)
t - a to get the 'cause' method ofpublic static java.lang.Throwable getRootCause(java.lang.Throwable t)
Uses Floyd’s cycle-finding algorithm to guard against circular cause chains without heap allocations.
t - the throwable to inspectt is nullpublic static java.lang.String getUserRelevantMessage(java.lang.Throwable t)
t - throwable to inspectt is nullgetUserRelevantMessage(Throwable, Class)public static java.lang.String getUserRelevantMessage(java.lang.Throwable t,
java.lang.Class<? extends java.lang.Throwable> preferType)
Message resolution precedence:
preferType (if specified).RuntimeException in the causal chain.Strips backend transport prefixes (such as ServerSideException markers)
before returning the final text.
t - throwable to inspectpreferType - preferred causal exception class to extract from; defaults to RuntimeException if nullt is null@Deprecated
public static boolean hasCauseOfClass(java.lang.Class clazz,
java.lang.Throwable t)
hasCauseOfClass(Throwable, Class) to follow standard (subject, predicate) parameter ordering.@Deprecated
public static java.lang.Throwable getCauseOfClass(java.lang.Class clazz,
java.lang.Throwable t)
getCauseOfClass(Throwable, Class) to follow standard (subject, predicate) parameter ordering.@Deprecated
public static java.lang.Throwable getDeepestCauseOfClass(java.lang.Class clazz,
java.lang.Throwable t)
getDeepestCauseOfClass(Throwable, Class) to follow standard (subject, predicate) parameter ordering.public static boolean hasCauseOfClass(java.lang.Throwable t,
java.lang.Class clazz)
t - the root throwable to inspectclazz - the target exception type to search forpublic static java.lang.Throwable getCauseOfClass(java.lang.Throwable t,
java.lang.Class clazz)
t - the root throwable to inspectclazz - the target exception type to search forpublic static java.lang.Throwable getDeepestCauseOfClass(java.lang.Throwable t,
java.lang.Class clazz)
t - the root throwable to inspectclazz - the target exception type to search forpublic static boolean isKnownWrapperException(java.lang.Throwable t)
t - throwable to evaluatet matches a registered wrapper exception class; false otherwisepublic static java.lang.String getStackTraceAsString(java.lang.Throwable t,
boolean filtered)
t - throwable to render; returns an empty string if nullfiltered - true to apply OutputConfiguration.DEFAULT_FILTERED_OUTPUT; false to retain all framespublic static java.lang.String getStackTraceAsString(java.lang.Throwable t)
t - throwable to render; returns an empty string if nullpublic static java.lang.String getStackTraceAsString(java.lang.Throwable t,
OutputConfiguration outputConfig)
t - throwable to render; returns an empty string if nulloutputConfig - format configuration and frame filter rules; defaults to full output if nullpublic static java.lang.String getStackTraceAsString(java.lang.Thread t,
boolean filtered)
t - thread to inspect; returns an empty string if nullfiltered - true to apply OutputConfiguration.DEFAULT_FILTERED_OUTPUT; false to retain all framespublic static java.lang.String getStackTraceAsString(java.lang.Thread t)
t - thread to inspect; returns an empty string if nullpublic static java.lang.String getStackTraceAsString(java.lang.Thread t,
OutputConfiguration outputConfig)
t - thread to inspect; returns an empty string if nulloutputConfig - format configuration and frame filter rules; defaults to full output if nullpublic static void dumpStack()
System.err.public static void dumpStack(java.lang.String msg)
System.err.msg - header message to precede the dump; defaults to current thread name if nullpublic static void dumpStack(java.lang.String msg,
java.io.PrintStream ps)
msg - header message to precede the dump; defaults to current thread name if nullps - target print stream; defaults to System.err if nullpublic static void dumpJVMStack()
System.err.public static void dumpJVMStack(java.io.PrintStream ps)
ps - target print stream; defaults to System.err if nullpublic static void printStackTrace(java.lang.Throwable t,
boolean filtered)
System.err, optionally applying default filtering.t - throwable to printfiltered - true to filter out framework and runtime noise; false to print all framespublic static void printStackTrace(java.lang.Throwable t,
java.io.PrintStream ps,
boolean filtered)
t - throwable to printps - destination print streamfiltered - true to filter out framework and runtime noise; false to print all framespublic static void printStackTrace(java.lang.Throwable t,
java.io.PrintStream ps)
t - throwable to printps - destination print streampublic static void printStackTrace(java.lang.Throwable t,
java.io.PrintStream ps,
OutputConfiguration outputConfig)
t - throwable to printps - destination print streamoutputConfig - format configuration and frame filters; defaults to full output if nullpublic static void printStackTrace(java.lang.Throwable t,
java.io.PrintStream ps,
OutputConfiguration outputConfig,
int upToFrame)
t - throwable to printps - destination print streamoutputConfig - format configuration and frame filters; defaults to full output if nullupToFrame - maximum frame index to print (exclusive); -1 to print through to the endpublic static void printStackTrace(java.lang.Throwable t,
java.io.PrintStream ps,
OutputConfiguration outputConfig,
int upToFrame,
int fromFrame)
t - throwable to printps - destination print streamoutputConfig - format configuration and frame filters; defaults to full output if nullupToFrame - maximum frame index to print (exclusive); -1 to print through to the endfromFrame - initial frame index to start printing from; -1 to start at index 0public static void printStackTraceAsCause(java.lang.String cm,
java.lang.Throwable t,
java.io.PrintWriter pw,
java.lang.StackTraceElement[] causedTrace,
OutputConfiguration outputConfig)
public static void printStackTrace(java.lang.Throwable t,
java.io.PrintWriter pw)
t - throwable to printpw - destination print writerpublic static void printStackTrace(java.lang.Throwable t,
java.io.PrintWriter pw,
OutputConfiguration outputConfig)
t - throwable to printpw - destination print writeroutputConfig - format configuration and frame filters; defaults to full output if nullpublic static void printStackTrace(java.lang.Throwable t,
java.io.PrintWriter pw,
OutputConfiguration outputConfig,
int upToFrame)
t - throwable to printpw - destination print writeroutputConfig - format configuration and frame filters; defaults to full output if nullupToFrame - maximum frame index to print (exclusive); -1 to print through to the endpublic static void printStackTrace(java.lang.Throwable t,
java.io.PrintWriter pw,
OutputConfiguration outputConfig,
int upToFrame,
int fromFrame)
t - throwable to printpw - destination print writeroutputConfig - format configuration and frame filters; defaults to full output if nullupToFrame - maximum frame index to print (exclusive); -1 to print through to the endfromFrame - initial frame index to start printing from; -1 to start at index 0public static void printStackTrace(java.lang.StackTraceElement[] stackTraceEls,
java.io.PrintWriter pw)
stackTraceEls - array of stack trace frames to outputpw - destination print writerpublic static void printStackTrace(java.lang.StackTraceElement[] stackTraceEls,
java.io.PrintWriter pw,
OutputConfiguration outputConfig)
stackTraceEls - array of stack trace frames to outputpw - destination print writeroutputConfig - format configuration and frame filters; defaults to full output if nullpublic static void printStackTrace(java.lang.StackTraceElement[] stackTraceEls,
java.io.PrintWriter pw,
OutputConfiguration outputConfig,
int upToFrame)
stackTraceEls - array of stack trace frames to outputpw - destination print writeroutputConfig - format configuration and frame filters; defaults to full output if nullupToFrame - maximum frame index to print (exclusive); -1 to print through to the endpublic static void printStackTrace(java.lang.StackTraceElement[] stackTraceEls,
java.io.PrintWriter pw,
OutputConfiguration outputConfig,
int upToFrame,
int fromFrame)
stackTraceEls - array of stack trace frames to outputpw - destination print writeroutputConfig - format configuration and frame filters; defaults to full output if nullupToFrame - maximum frame index to print (exclusive); -1 to print through to the endfromFrame - initial frame index to start printing from; -1 to start at index 0public static java.lang.Throwable filterStackTrace(java.lang.Throwable t)
Mutates the provided throwable in place and returns it for fluid chaining.
t - throwable whose traces are to be filtered; may be nullStackTraceFilter.STANDARD_FILTERSpublic static java.lang.Throwable filterStackTrace(java.lang.Throwable t,
StackTraceFilter[] filters)
Mutates the provided throwable in place and returns it for fluid chaining.
t - throwable whose traces are to be filtered; may be nullfilters - array of filter predicates to applypublic static java.lang.StackTraceElement[] filterStackTrace(java.lang.StackTraceElement[] stack)
stack - raw stack trace elements; may be nullStackTraceFilter.STANDARD_FILTERSpublic static java.lang.StackTraceElement[] filterStackTrace(java.lang.StackTraceElement[] stack,
StackTraceFilter[] filters)
stack - raw stack trace elements; may be nullfilters - array of filter predicates to applypublic static java.lang.StackTraceElement getStackTraceElement(java.lang.Throwable t,
java.lang.String declaringClass,
java.lang.String methodName)
t - throwable to inspectdeclaringClass - fully qualified class name to matchmethodName - method name to matchpublic static java.lang.StackTraceElement getStackTraceElement(java.lang.Throwable t,
java.lang.String declaringClass,
java.lang.String methodName,
java.lang.String fileName)
t - throwable to inspectdeclaringClass - fully qualified class name to matchmethodName - method name to matchfileName - source filename to match, or null to ignore file originpublic static void filterAndDumpStackTrace(java.lang.String str)
String and dumps it to STDOUT in
filtered form. Mainly for debugging purposes.str - the stacktrace as a Stringpublic static java.lang.String getErrortext(java.lang.Exception ex)
ex - exception to serializepublic static java.lang.String getErrortext(java.lang.Exception ex,
java.lang.String msg)
ex - exception to serializemsg - additional context message prefix, or nullpublic static boolean equals(java.lang.Throwable throwable1,
java.lang.Throwable throwable2)
Compares exception types, messages, stack trace element sequences, recursive cause structures, and suppressed exception arrays.
throwable1 - first throwable hierarchy to comparethrowable2 - second throwable hierarchy to compareCopyright © 2000-2026 OAshi S.à r.l. All Rights Reserved.