Enum Class ExceptionUtil

java.lang.Object
java.lang.Enum<ExceptionUtil>
com.linkedin.alpini.base.misc.ExceptionUtil
All Implemented Interfaces:
Serializable, Comparable<ExceptionUtil>, Constable

public enum ExceptionUtil extends Enum<ExceptionUtil>
  • Enum Constant Details

  • Method Details

    • values

      public static ExceptionUtil[] 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

      public static ExceptionUtil valueOf(String name)
      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 name
      NullPointerException - if the argument is null
    • getCause

      public static Throwable getCause(Throwable throwable, @Nonnull Class<?>... classes)
      Return the cause of the given Throwable 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

      Note that subclasses do not match. For example, looking for RuntimeException would not match to an IndexOutOfBoundsException. This is intentional.

      Parameters:
      throwable - Throwable to find the cause of
      classes - classes to look for in the cause stack
      Returns:
      cause of exception.
    • cause

      public static <E extends Throwable> E cause(Throwable throwable, @Nonnull Class<E> clazz)
      Return the specific cause of the given Throwable 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

      Note that subclasses do not match. For example, looking for RuntimeException would not match to an IndexOutOfBoundsException. This is intentional.

      Parameters:
      throwable - Throwable to find the cause of
      clazz - 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 given Throwable 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 of
      clazz - classes to look for in the cause stack
      Returns:
      cause of exception.
    • unwrapCompletion

      @Nonnull public static Throwable unwrapCompletion(@Nonnull Throwable throwable)
      Unwrap the cause of the given Throwable 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
      For example, consider "ex", a NullPointerException.
      • getCause(ex) --> returns the NullPointerException

      Parameters:
      throwable - Throwable to find the cause of
      Returns:
      cause of exception.
    • getStackTrace

      public static String getStackTrace(@Nonnull Throwable throwable)
    • 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 - StringBuilder
      element - StackTraceElement
      Returns:
      StringBuilder
    • withoutStackTrace

      public static <T extends Throwable> T withoutStackTrace(@Nonnull T throwable)
    • checkException

      public static <T> T checkException(@Nonnull Callable<T> callable, @Nonnull String exceptionMessage)
      Utility method to catch checked exceptions from a Callable and to rethrow as a RuntimeException.
      Parameters:
      callable - Callable with checked exception
      exceptionMessage - Message for thrown exception
      Returns:
      return value of callable