Package com.linkedin.alpini.base.misc
Enum ExceptionUtil
- java.lang.Object
-
- java.lang.Enum<ExceptionUtil>
-
- com.linkedin.alpini.base.misc.ExceptionUtil
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Comparable<ExceptionUtil>
public enum ExceptionUtil extends java.lang.Enum<ExceptionUtil>
-
-
Enum Constant Summary
Enum Constants Enum Constant Description SINGLETON
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringBuilder
appendStackTrace(java.lang.StringBuilder builder, java.lang.Throwable throwable)
static java.lang.StringBuilder
appendStackTraceElement(java.lang.StringBuilder builder, java.lang.StackTraceElement element)
Appends a StackTraceElement in the same way that StackTraceElement.toString() would except without creating intermediate String objects.static <E extends java.lang.Throwable>
Ecause(java.lang.Throwable throwable, java.lang.Class<E> clazz)
Return the specific cause of the givenThrowable
if the cause is one of the classes provided; otherwise return null.static <T> T
checkException(java.util.concurrent.Callable<T> callable, java.lang.String exceptionMessage)
Utility method to catch checked exceptions from a Callable and to rethrow as a RuntimeException.static java.lang.Throwable
getCause(java.lang.Throwable throwable, java.lang.Class<?>... classes)
Return the cause of the givenThrowable
if the cause is one of the classes provided; otherwise return the Throwable itself.static java.lang.String
getStackTrace(java.lang.Throwable throwable)
static <E extends java.lang.Throwable>
Eunwrap(java.lang.Throwable throwable, java.lang.Class<? extends E> clazz)
Unwrap the cause of the givenThrowable
if the cause is assignable to the provided class; otherwise return null.static java.lang.Throwable
unwrapCompletion(java.lang.Throwable throwable)
Unwrap the cause of the givenThrowable
if the cause is assignable to the provided class; otherwise return null.static ExceptionUtil
valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name.static ExceptionUtil[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.static <T extends java.lang.Throwable>
TwithoutStackTrace(T throwable)
-
-
-
Enum Constant Detail
-
SINGLETON
public static final ExceptionUtil SINGLETON
-
-
Method Detail
-
values
public static ExceptionUtil[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (ExceptionUtil c : ExceptionUtil.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static ExceptionUtil valueOf(java.lang.String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (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:
java.lang.IllegalArgumentException
- if this enum type has no constant with the specified namejava.lang.NullPointerException
- if the argument is null
-
getCause
public static java.lang.Throwable getCause(java.lang.Throwable throwable, @Nonnull java.lang.Class<?>... classes)
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
public static <E extends java.lang.Throwable> E cause(java.lang.Throwable throwable, @Nonnull java.lang.Class<E> clazz)
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 java.lang.Throwable> E unwrap(java.lang.Throwable throwable, @Nonnull java.lang.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
@Nonnull public static java.lang.Throwable unwrapCompletion(@Nonnull java.lang.Throwable throwable)
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
public static java.lang.String getStackTrace(@Nonnull java.lang.Throwable throwable)
-
appendStackTrace
@Nonnull public static java.lang.StringBuilder appendStackTrace(@Nonnull java.lang.StringBuilder builder, @Nonnull java.lang.Throwable throwable)
-
appendStackTraceElement
public static java.lang.StringBuilder appendStackTraceElement(java.lang.StringBuilder builder, java.lang.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
public static <T extends java.lang.Throwable> T withoutStackTrace(@Nonnull T throwable)
-
checkException
public static <T> T checkException(@Nonnull java.util.concurrent.Callable<T> callable, @Nonnull java.lang.String exceptionMessage)
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
-
-