@@ -67,6 +67,7 @@ Registering custom translators
67
67
68
68
If the default exception conversion policy described above is insufficient,
69
69
pybind11 also provides support for registering custom exception translators.
70
+
70
71
Similar to pybind11 classes, exception translators can be local to the module
71
72
they are defined in or global to the entire python session. To register a simple
72
73
exception conversion that translates a C++ exception into a new Python exception
@@ -93,7 +94,6 @@ parameter, a `handle`:
93
94
.. code-block :: cpp
94
95
95
96
py::register_exception<CppExp>(module, "PyExp", PyExc_RuntimeError);
96
- py::register_local_exception<CppExp>(module, "PyExp", PyExc_RuntimeError);
97
97
98
98
Then `PyExp ` can be caught both as `PyExp ` and `RuntimeError `.
99
99
@@ -170,10 +170,9 @@ section.
170
170
Local vs Global Exception Translators
171
171
=====================================
172
172
173
- Similar to how the ``py::module_local `` flag allows uesrs to limit a bound class
174
- to a single compiled module to prevent name collisions. When a global exception
175
- translator is registered, it will be applied across all modules in the reverse
176
- order of registration. This can create behavior where the order of module import
173
+ When a global exception translator is registered, it will be applied across all
174
+ modules in the reverse order of registration. When there are multiple pybind11
175
+ modules being loaded, this can create behavior where the order of module import
177
176
influences how exceptions are translated.
178
177
179
178
If module1 has the following translator:
@@ -202,7 +201,7 @@ and module2 has the following similar translator:
202
201
203
202
then which translator handles the invalid_argument will be determined by the
204
203
order that module1 and module2 are imported. Since exception translators are
205
- applied in the reverse order of registration, which ever module was imported
204
+ applied in the reverse order of registration, whichever module was imported
206
205
last will "win" and that translator will be applied.
207
206
208
207
If there are multiple pybind11 modules that share exception types (either
0 commit comments