public static String getMessage(Exception ex) {
    StringBuilder sb = new StringBuilder();
    sb.append(ex.getMessage());
    if (ex instanceof SQLException) {
      SQLException sqlEx = (SQLException)ex; 
      sb.append(" (SQLState=").append(sqlEx.getSQLState()).append(", ErrorCode=").append(sqlEx.getErrorCode()).append(")");
    }
    return sb.toString();
  }
Supports building resilient APIs by automatically retrying failed function calls.
standalone-metastore/metastore-server/src/main/java/org/apache/hadoop/hive/metastore/txn/retry/SqlRetryHandler.java