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
public class MongoException extends RuntimeException
Top level Exception for all Exceptions, server-side or client-side, that come from the driver.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static String
TRANSIENT_TRANSACTION_ERROR_LABEL
An error label indicating that the exception can be treated as a transient transaction error.static String
UNKNOWN_TRANSACTION_COMMIT_RESULT_LABEL
An error label indicating that the exception can be treated as an unknown transaction commit result.
-
Constructor Summary
Constructors Constructor Description MongoException(int code, String msg)
MongoException(int code, String msg, Throwable t)
MongoException(int code, String msg, BsonDocument response)
MongoException(String msg)
MongoException(String msg, Throwable t)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addLabel(String errorLabel)
Adds the given error label to the exception.protected void
addLabels(Collection<String> labels)
protected void
addLabels(BsonArray labels)
static MongoException
fromThrowable(Throwable t)
Static helper to create or cast a MongoException from a throwablestatic MongoException
fromThrowableNonNull(Throwable t)
Static helper to create or cast a MongoException from a throwableint
getCode()
Gets the exception codeSet<String>
getErrorLabels()
Gets the set of error labels associated with this exception.boolean
hasErrorLabel(String errorLabel)
Return true if the exception is labelled with the given error label, and false otherwise.void
removeLabel(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 Detail
-
TRANSIENT_TRANSACTION_ERROR_LABEL
public static final String TRANSIENT_TRANSACTION_ERROR_LABEL
An error label indicating that the exception can be treated as a transient transaction error.- Since:
- 3.8
- See Also:
hasErrorLabel(String)
, Constant Field Values
-
UNKNOWN_TRANSACTION_COMMIT_RESULT_LABEL
public static final String UNKNOWN_TRANSACTION_COMMIT_RESULT_LABEL
An error label indicating that the exception can be treated as an unknown transaction commit result.- Since:
- 3.8
- See Also:
hasErrorLabel(String)
, Constant Field Values
-
-
Constructor Detail
-
MongoException
public MongoException(String msg)
- Parameters:
msg
- the message
-
MongoException
public MongoException(int code, String msg)
- Parameters:
code
- the error codemsg
- the message
-
MongoException
public MongoException(String msg, Throwable t)
- Parameters:
msg
- the messaget
- the throwable cause
-
MongoException
public MongoException(int code, String msg, Throwable t)
- Parameters:
code
- the error codemsg
- the messaget
- the throwable cause
-
MongoException
public MongoException(int code, String msg, BsonDocument response)
- Parameters:
code
- the error codemsg
- the messageresponse
- the response- Since:
- 4.1
-
-
Method Detail
-
fromThrowable
@Nullable public static MongoException fromThrowable(@Nullable Throwable t)
Static helper to create or cast a MongoException from a throwable- Parameters:
t
- a throwable, which may be null- Returns:
- a MongoException
-
fromThrowableNonNull
public static MongoException fromThrowableNonNull(Throwable t)
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
public void addLabel(String errorLabel)
Adds the given error label to the exception.- Parameters:
errorLabel
- the non-null error label to add to the exception- Since:
- 3.8
-
removeLabel
public void removeLabel(String errorLabel)
Removes the given error label from the exception.- Parameters:
errorLabel
- the non-null error label to remove from the exception- Since:
- 3.8
-
getErrorLabels
public Set<String> 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
public boolean hasErrorLabel(String errorLabel)
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(BsonArray labels)
-
addLabels
protected void addLabels(Collection<String> labels)
-
-