Package org.junit.internal
Class Throwables
- java.lang.Object
-
- org.junit.internal.Throwables
-
public final class Throwables extends Object
Miscellaneous functions dealing withThrowable
.- Since:
- 4.12
- Author:
- kcooney@google.com (Kevin Cooney)
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
getStacktrace(Throwable exception)
Returns the stacktrace of the given Throwable as a String.static String
getTrimmedStackTrace(Throwable exception)
Gets a trimmed version of the stack trace of the given exception.static Exception
rethrowAsException(Throwable e)
Rethrows the givenThrowable
, allowing the caller to declare that it throwsException
.
-
-
-
Method Detail
-
rethrowAsException
public static Exception rethrowAsException(Throwable e) throws Exception
Rethrows the givenThrowable
, allowing the caller to declare that it throwsException
. This is useful when your callers have nothing reasonable they can do when aThrowable
is thrown. This is declared to returnException
so it can be used in athrow
clause:try { doSomething(); } catch (Throwable e} { throw Throwables.rethrowAsException(e); } doSomethingLater();
- Parameters:
e
- exception to rethrow- Returns:
- does not return anything
- Throws:
Exception
- Since:
- 4.12
-
getStacktrace
public static String getStacktrace(Throwable exception)
Returns the stacktrace of the given Throwable as a String.- Since:
- 4.13
-
getTrimmedStackTrace
public static String getTrimmedStackTrace(Throwable exception)
Gets a trimmed version of the stack trace of the given exception. Stack trace elements that are below the test method are filtered out.- Returns:
- a trimmed stack trace, or the original trace if trimming wasn't possible
-
-