MilvusClientException

A MilvusClientException instance represents a runtime exception thrown by the Milvus Java SDK v2 when a client- or server-side error occurs. The exception carries an ErrorCode describing the failure category and, optionally, the raw error codes returned by the Milvus server.

class io.milvus.v2.exception.MilvusClientException extends RuntimeException

Constructors

Constructs a MilvusClientException instance.

MilvusClientException(ErrorCode errorCode, String message)
MilvusClientException(ErrorCode errorCode, Throwable e)
MilvusClientException(ErrorCode errorCode, String message, int serverErrCode, int legacyServerCode)

PARAMETERS:

  • errorCode (ErrorCode) -

    The error code of this exception. Possible values are SUCCESS, COLLECTION_NOT_FOUND, SERVER_ERROR, INVALID_PARAMS, CLIENT_ERROR, RPC_ERROR, and TIMEOUT.

  • message (String) -

    The detail message of this exception.

  • e (Throwable) -

    The underlying cause of this exception.

  • serverErrCode (int) -

    The error code returned by the Milvus server.

  • legacyServerCode (int) -

    The legacy error code returned by older Milvus server versions.

Methods

  • getErrorCode() (ErrorCode) -

    Returns the error code of this exception.

  • getServerErrCode() (int) -

    Returns the error code returned by the Milvus server, or 0 if not set.

  • getLegacyServerCode() (int) -

    Returns the legacy error code returned by older Milvus server versions, or 0 if not set.

  • toString() (String) -

    Returns a string representation of this exception, which includes the error code name and the server error code when one is set.

ErrorCode

The ErrorCode enumeration classifies the failure category of a MilvusClientException.

ConstantValue
SUCCESS0
COLLECTION_NOT_FOUND1
SERVER_ERROR2
INVALID_PARAMS3
CLIENT_ERROR4
RPC_ERROR5
TIMEOUT6

Example

import io.milvus.v2.client.ConnectConfig;
import io.milvus.v2.client.MilvusClientV2;
import io.milvus.v2.exception.MilvusClientException;
import io.milvus.v2.service.collection.request.HasCollectionReq;

ConnectConfig connectConfig = ConnectConfig.builder()
        .uri("http://localhost:19530")
        .token("root:Milvus") // replace this with your token
        .build();

MilvusClientV2 client = new MilvusClientV2(connectConfig);

try {
    Boolean exists = client.hasCollection(HasCollectionReq.builder()
            .collectionName("test")
            .build());
    System.out.println(exists);
} catch (MilvusClientException e) {
    System.out.println("Error code: " + e.getErrorCode());
    System.out.println("Error message: " + e.getMessage());
}

Try Managed Milvus for Free

Zilliz Cloud is hassle-free, powered by Milvus and 10x faster.

Get Started
Feedback

Was this page helpful?