Package com.mongodb
Class MongoException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
com.mongodb.MongoException
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
MongoChangeStreamException,MongoClientException,MongoExecutionTimeoutException,MongoGridFSException,MongoIncompatibleDriverException,MongoInternalException,MongoInterruptedException,MongoServerException,MongoSocketException,MongoStalePrimaryException
Top level Exception for all Exceptions, server-side or client-side, that come from the driver.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe operation is safe to retry, that is, retry without rereading the relevant data or considering the semantics of the operation.static final StringServer is overloaded and shedding load.static final StringAn error label indicating that the exception can be treated as a transient transaction error.static final StringAn error label indicating that the exception can be treated as an unknown transaction commit result. -
Constructor Summary
ConstructorsConstructorDescriptionMongoException(int code, String msg) MongoException(int code, String msg, Throwable t) MongoException(int code, String msg, org.bson.BsonDocument response) MongoException(String msg) MongoException(String msg, Throwable t) -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds the given error label to the exception.protected voidaddLabels(Collection<String> labels) Add labels.protected voidaddLabels(org.bson.BsonArray labels) Add labels.static MongoExceptionStatic helper to create or cast a MongoException from a throwablestatic MongoExceptionStatic helper to create or cast a MongoException from a throwableintgetCode()Gets the exception codeGets the set of error labels associated with this exception.booleanhasErrorLabel(String errorLabel) Return true if the exception is labelled with the given error label, and false otherwise.voidremoveLabel(String errorLabel) Removes the given error label from the exception.Methods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Field Details
-
TRANSIENT_TRANSACTION_ERROR_LABEL
An error label indicating that the exception can be treated as a transient transaction error. See the documentation linked below for more information.- Since:
- 3.8
- See Also:
- MongoDB documentation
- TransientTransactionError
-
UNKNOWN_TRANSACTION_COMMIT_RESULT_LABEL
An error label indicating that the exception can be treated as an unknown transaction commit result. See the documentation linked below for more information.- Since:
- 3.8
- See Also:
- MongoDB documentation
- UnknownTransactionCommitResult
-
SYSTEM_OVERLOADED_ERROR_LABEL
Server is overloaded and shedding load. If an application retries explicitly, it should use exponential backoff because the server has indicated overload. This label on its own does not mean that the operation can be safely retried.- Since:
- 5.12
- See Also:
- MongoDB documentation
- overloadAwareServerSelectionEnabled
- Since server release
- 9.0
-
RETRYABLE_ERROR_LABEL
The operation is safe to retry, that is, retry without rereading the relevant data or considering the semantics of the operation.For more information on how transactions affect retries, see the documentation of the "TransientTransactionError", "UnknownTransactionCommitResult" error labels.
- Since:
- 5.12
- See Also:
- Since server release
- 9.0
-
-
Constructor Details
-
MongoException
- Parameters:
msg- the message
-
MongoException
- Parameters:
code- the error codemsg- the message
-
MongoException
- Parameters:
msg- the messaget- the throwable cause
-
MongoException
- Parameters:
code- the error codemsg- the messaget- the throwable cause
-
MongoException
- Parameters:
code- the error codemsg- the messageresponse- the response- Since:
- 4.1
-
-
Method Details
-
fromThrowable
Static helper to create or cast a MongoException from a throwable- Parameters:
t- a throwable, which may be null- Returns:
- a MongoException
-
fromThrowableNonNull
Static helper to create or cast a MongoException from a throwable- Parameters:
t- a throwable, which may not be null- Returns:
- a MongoException
- Since:
- 3.7
-
getCode
public int getCode()Gets the exception code- Returns:
- the error code.
-
addLabel
Adds the given error label to the exception.- Parameters:
errorLabel- the non-null error label to add to the exception- Since:
- 3.8
-
removeLabel
Removes the given error label from the exception.- Parameters:
errorLabel- the non-null error label to remove from the exception- Since:
- 3.8
-
getErrorLabels
Gets the set of error labels associated with this exception.- Returns:
- the error labels, which may not be null but may be empty
- Since:
- 3.8
-
hasErrorLabel
Return true if the exception is labelled with the given error label, and false otherwise.- Parameters:
errorLabel- the non-null error label- Returns:
- true if the exception is labelled with the given error label
- Since:
- 3.8
-
addLabels
protected void addLabels(org.bson.BsonArray labels) Add labels.- Parameters:
labels- the labels
-
addLabels
Add labels.- Parameters:
labels- the labels
-