@API(status=INTERNAL,
since="1.0")
public final class ExceptionUtils
extends java.lang.Object
These utilities are intended solely for usage within the JUnit framework itself. Any usage by external parties is not supported. Use at your own risk!
| Modifier and Type | Field and Description |
|---|---|
private static java.lang.String |
JUNIT_PLATFORM_LAUNCHER_PACKAGE_PREFIX |
private static java.util.function.Predicate<java.lang.String> |
STACK_TRACE_ELEMENT_FILTER |
| Modifier | Constructor and Description |
|---|---|
private |
ExceptionUtils() |
| Modifier and Type | Method and Description |
|---|---|
static java.util.List<java.lang.Throwable> |
findNestedThrowables(java.lang.Throwable rootThrowable)
Find all causes and suppressed exceptions in the stack trace of the
supplied
Throwable. |
static void |
pruneStackTrace(java.lang.Throwable throwable,
java.util.List<java.lang.String> classNames)
Prune the stack trace of the supplied
Throwable by removing
stack trace elements from the org.junit,
jdk.internal.reflect, and sun.reflect packages. |
static java.lang.String |
readStackTrace(java.lang.Throwable throwable)
Read the stacktrace of the supplied
Throwable into a String. |
private static <T extends java.lang.Throwable> |
throwAs(java.lang.Throwable t) |
static java.lang.RuntimeException |
throwAsUncheckedException(java.lang.Throwable t)
Throw the supplied
Throwable, masked as an
unchecked exception. |
private static final java.lang.String JUNIT_PLATFORM_LAUNCHER_PACKAGE_PREFIX
private static final java.util.function.Predicate<java.lang.String> STACK_TRACE_ELEMENT_FILTER
public static java.lang.RuntimeException throwAsUncheckedException(java.lang.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 statementprivate static <T extends java.lang.Throwable> void throwAs(java.lang.Throwable t)
throws T extends java.lang.Throwable
T extends java.lang.Throwablepublic static java.lang.String readStackTrace(java.lang.Throwable throwable)
Throwable into a String.@API(status=INTERNAL,
since="1.10")
public static void pruneStackTrace(java.lang.Throwable throwable,
java.util.List<java.lang.String> classNames)
Throwable by removing
stack trace elements from the org.junit,
jdk.internal.reflect, and sun.reflect packages. If a
StackTraceElement matching one of the supplied classNames
is encountered, all subsequent elements in the stack trace will be retained.
Additionally, all elements prior to and including the first JUnit Platform Launcher call will be removed.
throwable - the Throwable whose stack trace should be pruned;
never nullclassNames - the class names that should stop the pruning if encountered;
never null@API(status=INTERNAL,
since="1.10")
public static java.util.List<java.lang.Throwable> findNestedThrowables(java.lang.Throwable rootThrowable)
Throwable.rootThrowable - the Throwable to explore; never nullnull