public class ExceptionUtil extends Object
| Constructor and Description |
|---|
ExceptionUtil() |
| Modifier and Type | Method and Description |
|---|---|
static <EX extends Throwable> |
getDeepCause(Throwable t,
Class<? extends EX> clazz) |
static String |
getStackTrace(Throwable t) |
static String |
shortenStackTrace(String stackTrace,
String shallowestInterestingMethod)
Returns a shortened form of the given stack trace
by removing "boring" lines.
|
static String |
shortenStackTraceForServletCall(String stackTrace)
Returns a shortened form of the given stack trace,
omitting lines related to the servlet container before entry
into the servlet implementation.
|
static <EX extends Throwable> |
throwDeepCauseChecked(Throwable t,
Class<? extends EX> clazz)
Always
throw an exception; based on
t. |
static RuntimeException |
throwRootCauseUnchecked(Throwable t)
Does not return:
throws an unchecked exception, based on
t. |
static RuntimeException |
throwUnchecked(Throwable t)
Does not return:
throws an unchecked exception, based on
t. |
static Throwable |
withServletContainerStackOmitted(Throwable t)
Returns a version of the given throwable that prints with
a shortened stack trace, omitting lines related to the servlet
container before entry into the servlet implementation.
|
public static RuntimeException throwRootCauseUnchecked(Throwable t)
t.
First, the getCause chain of t
is followed to its base, and then,
an appropriate throwable exception is thrown, with preference
to throwing an Error.t - The underlying problem.Error - If there is an underlying ErrorRuntimeException - Otherwisepublic static RuntimeException throwUnchecked(Throwable t)
t.
If t can be thrown directly, it is,
otherwise it is wrapped as a RuntimeException.t - The underlying problem.Error - If t is an ErrorRuntimeException - Otherwisepublic static <EX extends Throwable> EX throwDeepCauseChecked(Throwable t, Class<? extends EX> clazz) throws EX extends Throwable
t.
The getCause chain of t
is analyzed, and then,
an appropriate Throwable is thrown, with preference as follows:
clazz (or a subtype).tEX - The type of exception thrown by the constructor of Vt - The underlying problem.clazz - The class of exception to look for. This clazz must not be abstract and must have
either a no element constructor or a constructor with one argument being a throwable.Error - If there is an underlying ErrorRuntimeException - If there is an underlying RuntimeException and no exception of type EXEX - If there is an appropriate exception or otherwiseIllegalArgumentException - If clazz is inappropriate (not always checked).EX extends Throwablepublic static <EX extends Throwable> EX getDeepCause(Throwable t, Class<? extends EX> clazz)
public static String shortenStackTrace(String stackTrace, String shallowestInterestingMethod)
stackTrace - The input stack trace, as produced by getStackTrace(Throwable)shallowestInterestingMethod - A fully qualified method name, as it appears in a stack trace: org.example.MyClass.myMethodpublic static String shortenStackTraceForServletCall(String stackTrace)
shortenStackTrace(String, String)public static Throwable withServletContainerStackOmitted(Throwable t)
shortenStackTrace(String, String)Copyright © 2019 TopQuadrant, Inc.. All rights reserved.