Class ExceptionUtils

java.lang.Object
org.junit.platform.commons.util.ExceptionUtils

@API(status=INTERNAL,
     since="1.0")
public final class ExceptionUtils
extends java.lang.Object
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 Type Method Description
    static java.lang.String readStackTrace​(java.lang.Throwable throwable)
    Read the stacktrace of the supplied Throwable into a String.
    static java.lang.RuntimeException throwAsUncheckedException​(java.lang.Throwable t)
    Throw the supplied Throwable, masked as an unchecked exception.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • throwAsUncheckedException

      public static java.lang.RuntimeException throwAsUncheckedException​(java.lang.Throwable t)
      Throw the supplied 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.

      Warning

      This method should be used sparingly.

      Parameters:
      t - the Throwable to throw as an unchecked exception; never null
      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 throw statement
    • readStackTrace

      public static java.lang.String readStackTrace​(java.lang.Throwable throwable)
      Read the stacktrace of the supplied Throwable into a String.