code: public static Throwable getNextThrowable(Throwable t) {
  
          Throwable nextThrowable = null;
          if (t != null) {
  
              // try getCause first.
              nextThrowable = t.getCause();
  
              if (nextThrowable == null) {
                  // if getCause returns null, look for the JDBC and JCA specific chained exceptions
                  // in case the resource adapter or database has not implemented getCause and initCause yet.
                  if (t instanceof SQLException) {
                      nextThrowable = ((SQLException) t).getNextException();
                  }
  
                  else if (t instanceof ResourceException) {
                      nextThrowable = ((ResourceException) t).getCause(); 
                  }
              }
          }
          return nextThrowable;
      }
docs: Finds the next Throwable object from the one provided.
  
  @param t The throwable to start with
  @return The next or linked, or initial cause.