Docs Menu

Docs HomePHP Library Manual

Exception Classes

On this page

  • MongoDB\Exception\BadMethodCallException
  • MongoDB\Exception\CreateEncryptedCollectionException
  • MongoDB\Exception\InvalidArgumentException
  • MongoDB\Exception\UnexpectedValueException
  • MongoDB\Exception\UnsupportedException
  • MongoDB\GridFS\Exception\CorruptFileException
  • MongoDB\GridFS\Exception\FileNotFoundException
  • MongoDB\Exception\Exception
  • MongoDB\Exception\RuntimeException
MongoDB\Exception\BadMethodCallException

This exception is thrown when an unsupported method is invoked on an object.

For example, using an unacknowledged write concern with MongoDB\Collection::insertMany() will return a MongoDB\InsertManyResult object. It is a logical error to call MongoDB\InsertManyResult::getInsertedCount(), since the number of inserted documents can only be determined from the response of an acknowledged write operation.

This class extends PHP's BadMethodCallException class and implements the library's Exception interface.


MongoDB\Exception\CreateEncryptedCollectionException

Thrown by MongoDB\Database::createEncryptedCollection() if any error is encountered while creating data keys or creating the collection. The original exception and modified encryptedFields option can be accessed via the getPrevious() and getEncryptedFields() methods, respectively.

This class extends the library's RuntimeException class.


MongoDB\Exception\InvalidArgumentException

Thrown for errors related to the parsing of parameters or options within the library.

This class extends the driver's InvalidArgumentException class and implements the library's Exception interface.


MongoDB\Exception\UnexpectedValueException

This exception is thrown when a command response from the server is malformed or not what the library expected. This exception means that an assertion in some operation, which abstracts a database command, has failed. It may indicate a corrupted BSON response or bug in the server, driver, or library.

This class extends the driver's UnexpectedValueException class and implements the library's Exception interface.


MongoDB\Exception\UnsupportedException

This exception is thrown if an option is used and not supported by the selected server. It is used sparingly in cases where silently ignoring the unsupported option might otherwise lead to unexpected behavior.

This class extends the library's RuntimeException class.

Note

Unlike InvalidArgumentException, which may be thrown when an operation's parameters and options are parsed during construction, the selected server is not known until an operation is executed.


MongoDB\GridFS\Exception\CorruptFileException

This exception is thrown if a GridFS file's metadata or chunk documents contain unexpected or invalid data.

When selecting a GridFS file, this may be thrown if a metadata field has an incorrect type or its value is out of range (e.g. negative length). When reading a GridFS file, this may be thrown if a chunk's index is out of sequence or its binary data's length out of range.

This class extends the library's RuntimeException class.


MongoDB\GridFS\Exception\FileNotFoundException

This exception is thrown if no GridFS file was found for the selection criteria (e.g. id, filename).

This class extends the library's RuntimeException class.


MongoDB\Exception\Exception

This interface extends the driver's Exception interface and is implemented by all exception classes within the library.


MongoDB\Exception\RuntimeException

This class extends the driver's RuntimeException class, which in turn extends PHP's RuntimeException class.

←  MongoDB\with_transaction()Frequently Asked Questions →