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
public class MongoCommandException extends MongoServerException
An exception indicating that a command sent to a MongoDB server returned a failure.- Since:
- 2.13
- See Also:
- Serialized Form
-
-
Field Summary
-
Fields inherited from class com.mongodb.MongoException
TRANSIENT_TRANSACTION_ERROR_LABEL, UNKNOWN_TRANSACTION_COMMIT_RESULT_LABEL
-
-
Constructor Summary
Constructors Constructor Description MongoCommandException(BsonDocument response, ServerAddress address)
Construct a new instance with the CommandResult from a failed command
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
getErrorCode()
Gets the error code associated with the command failure.String
getErrorCodeName()
Gets the name associated with the error code.String
getErrorMessage()
Gets the error message associated with the command failure.BsonDocument
getResponse()
For internal use only.-
Methods inherited from class com.mongodb.MongoServerException
getServerAddress
-
Methods inherited from class com.mongodb.MongoException
addLabel, 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 Detail
-
MongoCommandException
public MongoCommandException(BsonDocument response, ServerAddress address)
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 Detail
-
getErrorCode
public int getErrorCode()
Gets the error code associated with the command failure.- Returns:
- the error code
-
getErrorCodeName
public String getErrorCodeName()
Gets the name associated with the error code.- Returns:
- the error code name, which may be the empty string
- Since:
- 3.8
- Since server release
- 3.4
-
getErrorMessage
public String getErrorMessage()
Gets the error message associated with the command failure.- Returns:
- the error message
-
getResponse
public BsonDocument getResponse()
For internal use only.- Returns:
- the full response to the command failure.
-
-