Class ExceptionUtils

java.lang.Object
org.jppf.utils.ExceptionUtils

public final class ExceptionUtils extends Object
This class provides a set of utility methods for manipulating Throwable objects.
Author:
Laurent Cohen
  • Method Details

    • getStackTrace

      public static String getStackTrace(Throwable t)
      Get a throwable's stack trace.
      Parameters:
      t - the throwable to get the stack trace from.
      Returns:
      the stack trace as a string.
    • getCallStack

      public static String getCallStack()
      Get the call stack for the current thread.
      Returns:
      the call stack as a string.
    • getMessage

      public static String getMessage(Throwable t)
      Get the message of the specified Throwable along with its class name.
      Parameters:
      t - the Throwable object from which to get the message.
      Returns:
      a formatted message from the Throwable.
    • toException

      public static Exception toException(Throwable throwable)
      Converts a generic Throwable into an Exception. If throwable is already an instance of Exception, it is returned as is.
      Parameters:
      throwable - the Throwable to convert.
      Returns:
      an (possibly new) Exception wrapping the Throwable as its cause.
      Since:
      4.0
    • toException

      public static Exception toException(String message, Throwable throwable)
      Converts a generic Throwable into an Exception.
      Parameters:
      throwable - the Throwable to convert.
      message - the message of the created exception.
      Returns:
      a new Exception wrapping the Throwable as its cause.
      Since:
      4.0
    • toRuntimeException

      public static RuntimeException toRuntimeException(Throwable throwable)
      Converts a generic Throwable into a RuntimeException. If throwable is already an instance of RuntimeException, it is returned as is.
      Parameters:
      throwable - the Throwable to convert.
      Returns:
      a (possibly new) RuntimeException wrapping the Throwable as its cause.
      Since:
      4.0
    • toRuntimeException

      public static RuntimeException toRuntimeException(String message, Throwable throwable)
      Converts a generic Throwable into a RuntimeException.
      Parameters:
      throwable - the Throwable to convert.
      message - the message of the xcreated exception.
      Returns:
      a new RuntimeException wrapping the Throwable as its cause.
      Since:
      4.0
    • toException

      public static <E extends Exception> E toException(Throwable throwable, Class<E> clazz)
      Converts a generic Throwable into an Exception of the specified class. If throwable is already an instance of the specified exception class, it is returned as is.
      Type Parameters:
      E - the type of exception to return.
      Parameters:
      throwable - the Throwable to convert.
      clazz - the class of the exception to convert to.
      Returns:
      a (possibly new) exception of the specified class wrapping the Throwable as its cause, or null if an exception of this class cannot be constructed.
      Since:
      4.0
    • toException

      public static <E extends Exception> E toException(String message, Throwable throwable, Class<E> clazz)
      Converts a generic Throwable into an Exception of the specified class.
      Type Parameters:
      E - the type of exception to return.
      Parameters:
      message - the message of the xcreated exception.
      throwable - the Throwable to convert.
      clazz - the class of the exception to convert to.
      Returns:
      a new exception of the specified class wrapping the Throwable as its cause, or null if an exception of this class cannot be constructed.
      Since:
      4.0