Package com.mongodb
Class MongoCommandException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
com.mongodb.MongoException
com.mongodb.MongoServerException
com.mongodb.MongoCommandException
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
MongoNodeIsRecoveringException
,MongoNotPrimaryException
An exception indicating that a command sent to a MongoDB server returned a failure.
- Since:
- 2.13
-
Field Summary
Fields inherited from class com.mongodb.MongoException
TRANSIENT_TRANSACTION_ERROR_LABEL, UNKNOWN_TRANSACTION_COMMIT_RESULT_LABEL
-
Constructor Summary
ConstructorDescriptionMongoCommandException
(BsonDocument response, ServerAddress address) Construct a new instance with the CommandResult from a failed command -
Method Summary
Modifier and TypeMethodDescriptionint
Gets the error code associated with the command failure.Gets the name associated with the error code.Gets the error message associated with the command failure.For internal use only.Methods inherited from class com.mongodb.MongoServerException
getServerAddress
Methods inherited from class com.mongodb.MongoException
addLabel, addLabels, addLabels, fromThrowable, fromThrowableNonNull, getCode, getErrorLabels, hasErrorLabel, removeLabel
Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
MongoCommandException
Construct a new instance with the CommandResult from a failed command- Parameters:
response
- the command responseaddress
- the address of the server that generated the response
-
-
Method Details
-
getErrorCode
public int getErrorCode()Gets the error code associated with the command failure.- Returns:
- the error code
-
getErrorCodeName
Gets the name associated with the error code.- Overrides:
getErrorCodeName
in classMongoServerException
- Returns:
- the error code name, which may be the empty string
- Since:
- 3.8
- Since server release
- 3.4
-
getErrorMessage
Gets the error message associated with the command failure.- Returns:
- the error message
-
getResponse
For internal use only.- Returns:
- the full response to the command failure.
-