类 Throwables


  • public class Throwables
    extends java.lang.Object
    Utils method for throwable
    • 构造器概要

      构造器 
      构造器 说明
      Throwables()  
    • 方法概要

      所有方法 静态方法 具体方法 
      修饰符和类型 方法 说明
      static <T extends java.lang.Throwable>
      java.util.Optional<T>
      getCauseOf​(java.lang.Throwable throwable, java.lang.Class<T> cls)
      Get ancestor cause, util the cause is specific type, or throwable has no cause.
      static java.lang.Throwable getRootCause​(java.lang.Throwable throwable)
      Get root cause of throwable.
      static java.lang.String getStackTrace​(java.lang.Throwable t)
      Get stack trace as string.
      static java.lang.RuntimeException sneakyThrow​(java.lang.Throwable t)
      Throw the throwable without need to add throws clause to method signature.
      static <T extends java.lang.Throwable>
      void
      throwIf​(java.lang.Throwable throwable, java.lang.Class<T> cls)
      If throwable is type T, throw it.
      static void throwIfUnchecked​(java.lang.Throwable throwable)
      If is unchecked (Error, or RuntimeException), throw the throwable
      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 构造器详细资料

      • Throwables

        public Throwables()
    • 方法详细资料

      • sneakyThrow

        public static java.lang.RuntimeException sneakyThrow​(java.lang.Throwable t)
        Throw the throwable without need to add throws clause to method signature. Usually, it should use like this:

        throw Throwables.sneakyThrow(e);

        参数:
        t - the exception to throw, should not be null
      • throwIfUnchecked

        public static void throwIfUnchecked​(java.lang.Throwable throwable)
        If is unchecked (Error, or RuntimeException), throw the throwable
        参数:
        throwable - the throwable
      • throwIf

        public static <T extends java.lang.Throwable> void throwIf​(java.lang.Throwable throwable,
                                                                   java.lang.Class<T> cls)
                                                            throws T extends java.lang.Throwable
        If throwable is type T, throw it.
        类型参数:
        T - the type
        参数:
        throwable - the throwable
        cls - the type class
        抛出:
        T - exception
        T extends java.lang.Throwable
      • getRootCause

        public static java.lang.Throwable getRootCause​(java.lang.Throwable throwable)
        Get root cause of throwable. If throwable do not have a root cause, return its self.
        参数:
        throwable - the throwable, cannot be null
        返回:
        the root cause.
      • getCauseOf

        public static <T extends java.lang.Throwable> java.util.Optional<T> getCauseOf​(java.lang.Throwable throwable,
                                                                                       java.lang.Class<T> cls)
        Get ancestor cause, util the cause is specific type, or throwable has no cause.
        参数:
        throwable - the throwable, cannot be null
        返回:
        the cause with specific type, or empty if not such cause.
      • getStackTrace

        public static java.lang.String getStackTrace​(java.lang.Throwable t)
        Get stack trace as string.
        参数:
        t - the throwable, cannot be null
        返回:
        the string represent stacktrace of throwable