Class ThrowableUtils

  • All Implemented Interfaces:
    Utils

    public abstract class ThrowableUtils
    extends java.lang.Object
    implements Utils
    The uitlities class for Throwable
    Since:
    1.0.0
    Author:
    Mercy
    See Also:
    Throwable
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.Throwable getRootCause​(java.lang.Throwable throwable)
      Retrieves the root cause of the given Throwable by traversing the cause chain until a throwable with no cause is found.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • getRootCause

        public static java.lang.Throwable getRootCause​(java.lang.Throwable throwable)
        Retrieves the root cause of the given Throwable by traversing the cause chain until a throwable with no cause is found.

        Example Usage

        
           Exception root = new IllegalArgumentException("root");
           Exception wrapped = new RuntimeException("wrapped", root);
           Throwable result = ThrowableUtils.getRootCause(wrapped);
           System.out.println(result.getMessage()); // "root"
         
        Parameters:
        throwable - the throwable whose root cause is to be determined; must not be null
        Returns:
        the root cause of the throwable chain
        Since:
        1.0.0