public static BatchUpdateException batchUpdateError(Throwable e, long[] updateCounts) {
        if (e == null) {
            return new BatchUpdateException("Something went wrong when performing batch update", SQL_STATE_CLIENT_ERROR,
                    0, updateCounts, null);
        } else if (e instanceof BatchUpdateException) {
            return (BatchUpdateException) e;
        } else if (e instanceof SQLException) {
            SQLException sqlExp = (SQLException) e;
            return new BatchUpdateException(sqlExp.getMessage(), sqlExp.getSQLState(), sqlExp.getErrorCode(),
                    updateCounts, null);
        }

        Throwable cause = e.getCause();
        if (e instanceof BatchUpdateException) {
            return (BatchUpdateException) e;
        } else if (cause instanceof ClickHouseException) {
            return batchUpdateError(cause, updateCounts);
        } else if (cause instanceof SQLException) {
            SQLException sqlExp = (SQLException) cause;
            return new BatchUpdateException(sqlExp.getMessage(), sqlExp.getSQLState(), sqlExp.getErrorCode(),
                    updateCounts, null);
        } else if (cause == null) {
            cause = e;
        }

        return new BatchUpdateException("Unexpected error", SQL_STATE_SQL_ERROR, 0, updateCounts, cause);
    }
Helper class for building {@link SQLException}.
clickhouse-jdbc/src/main/java/com/clickhouse/jdbc/SqlExceptionUtils.java