code: public static SQLException unwrapSQLException(Throwable throwable) {
          if (throwable == null) {
              return null;
          } else if (throwable instanceof SQLException) {
              return (SQLException) throwable;
          } else if (throwable.getCause() != null) {
              // recursive call to unwrap the cause
              return unwrapSQLException(throwable.getCause());
          } else {
              // didn't find any SQLException in the cause stack
              return null;
          }
      }
docs: Looks for SQLException in the cause chain.
  
  @return Found SQLException in the cause chain, or null if none found