类 ExceptionUtils

java.lang.Object
cn.taketoday.util.ExceptionUtils

public abstract class ExceptionUtils extends Object
作者:
TODAY
2018-11-13 21:25
  • 构造器详细资料

    • ExceptionUtils

      public ExceptionUtils()
  • 方法详细资料

    • unwrapThrowable

      public static Throwable unwrapThrowable(Throwable ex)
      Unwrap
      参数:
      ex - target Throwable
      返回:
      unwrapped Throwable
    • buildMessage

      public static String buildMessage(String message, Throwable cause)
      Build a message for the given base message and root cause.
      参数:
      message - the base message
      cause - the root cause
      返回:
      the full exception message
      从以下版本开始:
      3.0
    • getRootCause

      public static Throwable getRootCause(Throwable original)
      Retrieve the innermost cause of the given exception, if any.
      参数:
      original - the original exception to introspect
      返回:
      the innermost exception, or null if none
      从以下版本开始:
      3.0
    • getMostSpecificCause

      public static Throwable getMostSpecificCause(Throwable original)
      Retrieve the most specific cause of the given exception, that is, either the innermost cause (root cause) or the exception itself.

      Differs from getRootCause(java.lang.Throwable) in that it falls back to the original exception if there is no root cause.

      参数:
      original - the original exception to introspect
      返回:
      the most specific cause (never null)
      从以下版本开始:
      3.0
    • sneakyThrow

      public static RuntimeException sneakyThrow(Throwable t)
      Throws any throwable 'sneakily' - you don't need to catch it, nor declare that you throw it onwards. The exception is still thrown - javac will just stop whining about it.

      Example usage:

         public void run() {
           throw sneakyThrow(new IOException("You don't need to catch me!"));
         }
       

      NB: The exception is not wrapped, ignored, swallowed, or redefined. The JVM actually does not know or care about the concept of a 'checked exception'. All this method does is hide the act of throwing a checked exception from the java compiler.

      Note that this method has a return type of RuntimeException; it is advised you always call this method as argument to the throw statement to avoid compiler errors regarding no return statement and similar problems. This method won't of course return an actual RuntimeException - it never returns, it always throws the provided exception.

      参数:
      t - The throwable to throw without requiring you to catch its type.
      返回:
      A dummy RuntimeException; this method never returns normally, it always throws an exception!
      从以下版本开始:
      4.0
    • sneakyThrow0

      private static <T extends Throwable> T sneakyThrow0(Throwable t) throws T
      抛出:
      T extends Throwable
    • sneakyThrow

      public static void sneakyThrow(ExceptionUtils.Action action)
      从以下版本开始:
      4.0
    • sneakyThrow

      public static <T> T sneakyThrow(Callable<T> action)
      从以下版本开始:
      4.0