Package com.linkedin.alpini.base.misc
Enum Class ExceptionUtil
- All Implemented Interfaces:
Serializable
,Comparable<ExceptionUtil>
,Constable
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringBuilder
appendStackTrace
(StringBuilder builder, Throwable throwable) static StringBuilder
appendStackTraceElement
(StringBuilder builder, StackTraceElement element) Appends a StackTraceElement in the same way that StackTraceElement.toString() would except without creating intermediate String objects.static <E extends Throwable>
EReturn the specific cause of the givenThrowable
if the cause is one of the classes provided; otherwise return null.static <T> T
checkException
(Callable<T> callable, String exceptionMessage) Utility method to catch checked exceptions from a Callable and to rethrow as a RuntimeException.static Throwable
Return the cause of the givenThrowable
if the cause is one of the classes provided; otherwise return the Throwable itself.static String
getStackTrace
(Throwable throwable) static <E extends Throwable>
EUnwrap the cause of the givenThrowable
if the cause is assignable to the provided class; otherwise return null.static Throwable
unwrapCompletion
(Throwable throwable) Unwrap the cause of the givenThrowable
if the cause is assignable to the provided class; otherwise return null.static ExceptionUtil
Returns the enum constant of this class with the specified name.static ExceptionUtil[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.static <T extends Throwable>
TwithoutStackTrace
(T throwable)
-
Enum Constant Details
-
SINGLETON
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum class has no constant with the specified nameNullPointerException
- if the argument is null
-
getCause
Return the cause of the givenThrowable
if the cause is one of the classes provided; otherwise return the Throwable itself. If there are multiple matches, this method will return the cause deepest in the getCause() stack (e.g. closest to the root cause). For example, consider "ex", a RuntimeException caused by SQLException caused by ConnectException.-
getCause(ex, ConnectException.class) --> returns the ConnectException
getCause(ex, SomeOtherException.class, ConnectException.class) --> returns the ConnectException
getCause(ex, SQLException.class, ConnectException.class) --> returns the ConnectException
getCause(ex, ConnectException.class, SQLException.class) --> returns the ConnectException
getCause(ex, SomeOtherException.class) --> returns ex
- Parameters:
throwable
- Throwable to find the cause ofclasses
- classes to look for in the cause stack- Returns:
- cause of exception.
-
cause
Return the specific cause of the givenThrowable
if the cause is one of the classes provided; otherwise return null. If there are multiple matches, this method will return the cause deepest in the getCause() stack (e.g. closest to the root cause). For example, consider "ex", a RuntimeException caused by SQLException caused by ConnectException.-
cause(ex, ConnectException.class) --> returns the ConnectException
cause(ex, SomeOtherException.class) --> returns null
- Parameters:
throwable
- Throwable to find the cause ofclazz
- classes to look for in the cause stack- Returns:
- cause of exception.
-
unwrap
public static <E extends Throwable> E unwrap(Throwable throwable, @Nonnull Class<? extends E> clazz) Unwrap the cause of the givenThrowable
if the cause is assignable to the provided class; otherwise return null. If there are multiple matches, this method will return the cause deepest in the getCause() stack (e.g. closest to the root cause). For example, consider "ex", a RuntimeException caused by SQLException caused by ConnectException.-
getCause(ex, ConnectException.class) --> returns the ConnectException
getCause(ex, SomeOtherException.class) --> returns null
- Parameters:
throwable
- Throwable to find the cause ofclazz
- classes to look for in the cause stack- Returns:
- cause of exception.
-
unwrapCompletion
Unwrap the cause of the givenThrowable
if the cause is assignable to the provided class; otherwise return null. If there are multiple matches, this method will return the cause deepest in the getCause() stack (e.g. closest to the root cause). For example, consider "ex", a RuntimeException caused by SQLException caused by ConnectException.-
getCause(ex) --> returns the ConnectException
-
getCause(ex) --> returns the NullPointerException
- Parameters:
throwable
- Throwable to find the cause of- Returns:
- cause of exception.
-
getStackTrace
-
appendStackTrace
@Nonnull public static StringBuilder appendStackTrace(@Nonnull StringBuilder builder, @Nonnull Throwable throwable) -
appendStackTraceElement
public static StringBuilder appendStackTraceElement(StringBuilder builder, StackTraceElement element) Appends a StackTraceElement in the same way that StackTraceElement.toString() would except without creating intermediate String objects.- Parameters:
builder
- StringBuilderelement
- StackTraceElement- Returns:
- StringBuilder
-
withoutStackTrace
-
checkException
Utility method to catch checked exceptions from a Callable and to rethrow as a RuntimeException.- Parameters:
callable
- Callable with checked exceptionexceptionMessage
- Message for thrown exception- Returns:
- return value of callable
-