Skip to content

Commit 3698343

Browse files
committed
PHPLIB-235: Document exception classes and interfaces
1 parent 2201f47 commit 3698343

File tree

2 files changed

+112
-1
lines changed

2 files changed

+112
-1
lines changed

docs/reference.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ Reference
66

77
.. toctree::
88
:titlesonly:
9-
9+
1010
/reference/bson
1111
/reference/class/MongoDBClient
1212
/reference/class/MongoDBDatabase
1313
/reference/class/MongoDBCollection
1414
/reference/class/MongoDBGridFSBucket
15+
/reference/exception-classes

docs/reference/exception-classes.txt

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
=================
2+
Exception Classes
3+
=================
4+
5+
.. default-domain:: mongodb
6+
7+
.. contents:: On this page
8+
:local:
9+
:backlinks: none
10+
:depth: 1
11+
:class: singlecol
12+
13+
MongoDB\\Exception\\BadMethodCallException
14+
------------------------------------------
15+
16+
.. phpclass:: MongoDB\\Exception\\BadMethodCallException
17+
18+
This exception is thrown when an unsupported method is invoked on an object.
19+
20+
For example, using an unacknowledged write concern with
21+
:phpmethod:`MongoDB\\Collection::insertMany()` will return a
22+
:phpclass:`MongoDB\\InsertManyResult` object. It is a logical error to call
23+
:phpmethod:`MongoDB\\InsertManyResult::getInsertedCount()`, since the number
24+
of inserted documents can only be determined from the response of an
25+
acknowledged write operation.
26+
27+
This class extends PHP's :php:`BadMethodCallException
28+
<badmethodcallexception>` class and implements the library's
29+
:phpclass:`Exception <MongoDB\\Exception\\Exception>` interface.
30+
31+
----
32+
33+
MongoDB\\Exception\\InvalidArgumentException
34+
--------------------------------------------
35+
36+
.. phpclass:: MongoDB\\Exception\\InvalidArgumentException
37+
38+
Thrown for errors related to the parsing of parameters or options within the
39+
library.
40+
41+
This class extends the driver's :php:`InvalidArgumentException
42+
<mongodb-driver-exception-invalidargumentexception>` class and implements the
43+
library's :phpclass:`Exception <MongoDB\\Exception\\Exception>` interface.
44+
45+
----
46+
47+
MongoDB\\Exception\\UnexpectedValueException
48+
--------------------------------------------
49+
50+
.. phpclass:: MongoDB\\Exception\\UnexpectedValueException
51+
52+
This exception is thrown when a command response from the server is
53+
malformed or not what the library expected. This exception means that an
54+
assertion in some operation, which abstracts a database command, has failed.
55+
It may indicate a corrupted BSON response or bug in the server, driver, or
56+
library.
57+
58+
This class extends the driver's :php:`UnexpectedValueException
59+
<mongodb-driver-exception-unexpectedvalueexception>` class and implements the
60+
library's :phpclass:`Exception <MongoDB\\Exception\\Exception>` interface.
61+
62+
----
63+
64+
MongoDB\\Exception\\UnsupportedException
65+
----------------------------------------
66+
67+
.. phpclass:: MongoDB\\Exception\\UnsupportedException
68+
69+
This exception is thrown if an option is used and not supported by the
70+
selected server. It is used sparingly in cases where silently ignoring the
71+
unsupported option might otherwise lead to unexpected behavior.
72+
73+
For example, the ``collation`` option for
74+
:phpmethod:`MongoDB\\Collection::deleteOne()` is only supported by
75+
MongoDB 3.4+. Since collation determines how a document is matched, silently
76+
ignoring the option for an older server version could result in an
77+
unintended document being deleted.
78+
79+
This class extends the library's :phpclass:`RuntimeException
80+
<MongoDB\\Exception\\RuntimeException>` class and implements the
81+
library's :phpclass:`Exception <MongoDB\\Exception\\Exception>` interface.
82+
83+
.. note::
84+
85+
Unlike :phpclass:`InvalidArgumentException
86+
<MongoDB\\Exception\\InvalidArgumentException>`, which may be thrown when
87+
an operation's parameters and options are parsed during construction, the
88+
selected server is not known until an operation is executed.
89+
90+
----
91+
92+
MongoDB\\Exception\\Exception
93+
-----------------------------
94+
95+
.. phpclass:: MongoDB\\Exception\\Exception
96+
97+
This interface extends the driver's :php:`Exception
98+
<mongodb-driver-exception-exception>` interface and is implemented by all
99+
exception classes within the library.
100+
101+
----
102+
103+
MongoDB\\Exception\\RuntimeException
104+
------------------------------------
105+
106+
.. phpclass:: MongoDB\\Exception\\RuntimeException
107+
108+
This class extends the driver's :php:`RuntimeException
109+
<mongodb-driver-exception-runtimeexception>` class, which in turn extends
110+
PHP's :php:`RuntimeException <runtimeexception>` class.

0 commit comments

Comments
 (0)