java.lang.Object
org.junit.platform.commons.util.ExceptionUtils
Collection of utilities for working with exceptions.
DISCLAIMER
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!
- Since:
- 1.0
-
Method Summary
Modifier and TypeMethodDescriptionfindNestedThrowables(Throwable rootThrowable) Find all causes and suppressed exceptions in the backtrace of the suppliedThrowable.static voidpruneStackTrace(Throwable throwable, Predicate<String> stackTraceElementFilter) static StringreadStackTrace(Throwable throwable) Read the stacktrace of the suppliedThrowableinto a String.static RuntimeExceptionThrow the suppliedThrowable, masked as an unchecked exception.
-
Method Details
-
throwAsUncheckedException
Throw the suppliedThrowable, masked as an unchecked exception.The supplied
Throwablewill 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.Warning
This method should be used sparingly.
- Parameters:
t- theThrowableto throw as an unchecked exception; nevernull- Returns:
- this method always throws an exception and therefore never
returns anything; the return type is merely present to allow this
method to be supplied as the operand in a
throwstatement
-
readStackTrace
Read the stacktrace of the suppliedThrowableinto a String. -
pruneStackTrace
@API(status=INTERNAL, since="5.10") public static void pruneStackTrace(Throwable throwable, Predicate<String> stackTraceElementFilter) Prune the stack trace of the suppliedThrowableby filtering its elements using the suppliedPredicate, except fororg.junit.jupiter.api.Assertionsandorg.junit.jupiter.api.Assumptionsthat will always remain present.Additionally, all elements prior to and including the first JUnit Launcher call will be removed.
- Parameters:
throwable- theThrowablewhose stack trace should be pruned; nevernullstackTraceElementFilter- thePredicateused to filter elements of the stack trace; nevernull- Since:
- 5.10
-
findNestedThrowables
@API(status=INTERNAL, since="5.10") public static List<Throwable> findNestedThrowables(Throwable rootThrowable) Find all causes and suppressed exceptions in the backtrace of the suppliedThrowable.- Parameters:
rootThrowable- theThrowableto explore; nevernull- Returns:
- an immutable list of all throwables found, including the supplied
one; never
null - Since:
- 5.10
-