@@ -75,6 +75,7 @@ Registering custom translators
75
75
76
76
If the default exception conversion policy described above is insufficient,
77
77
pybind11 also provides support for registering custom exception translators.
78
+
78
79
Similar to pybind11 classes, exception translators can be local to the module
79
80
they are defined in or global to the entire python session. To register a simple
80
81
exception conversion that translates a C++ exception into a new Python exception
@@ -101,7 +102,6 @@ parameter, a `handle`:
101
102
.. code-block :: cpp
102
103
103
104
py::register_exception<CppExp>(module, "PyExp", PyExc_RuntimeError);
104
- py::register_local_exception<CppExp>(module, "PyExp", PyExc_RuntimeError);
105
105
106
106
Then `PyExp ` can be caught both as `PyExp ` and `RuntimeError `.
107
107
@@ -178,10 +178,9 @@ section.
178
178
Local vs Global Exception Translators
179
179
=====================================
180
180
181
- Similar to how the ``py::module_local `` flag allows uesrs to limit a bound class
182
- to a single compiled module to prevent name collisions. When a global exception
183
- translator is registered, it will be applied across all modules in the reverse
184
- order of registration. This can create behavior where the order of module import
181
+ When a global exception translator is registered, it will be applied across all
182
+ modules in the reverse order of registration. When there are multiple pybind11
183
+ modules being loaded, this can create behavior where the order of module import
185
184
influences how exceptions are translated.
186
185
187
186
If module1 has the following translator:
@@ -210,7 +209,7 @@ and module2 has the following similar translator:
210
209
211
210
then which translator handles the invalid_argument will be determined by the
212
211
order that module1 and module2 are imported. Since exception translators are
213
- applied in the reverse order of registration, which ever module was imported
212
+ applied in the reverse order of registration, whichever module was imported
214
213
last will "win" and that translator will be applied.
215
214
216
215
If there are multiple pybind11 modules that share exception types (either
0 commit comments