@@ -9,12 +9,16 @@ that will trap C++ exceptions, translate them to the corresponding Python except
9
9
and raise them so that Python code can handle them.
10
10
11
11
pybind11 defines translations for ``std::exception `` and its standard
12
- subclasses, and several special exception classes that translate to specific
13
- Python exceptions. Note that these are not actually Python exceptions, so they
12
+ subclasses (see [translate_exception ]_) and several special exception classes
13
+ that translate to specific Python exceptions (see [PYBIND11_RUNTIME_EXCEPTION ]_).
14
+ Note that these are not actually Python exceptions, so they
14
15
cannot be examined using the Python C API. Instead, they are pure C++ objects
15
16
that pybind11 will translate the corresponding Python exception when they arrive
16
17
at its exception handler.
17
18
19
+ .. [translate_exception ] https://github.com/pybind/pybind11/search?q=translate_exception
20
+ .. [PYBIND11_RUNTIME_EXCEPTION ] https://github.com/pybind/pybind11/blob/master/include/pybind11/detail/common.h
21
+
18
22
.. tabularcolumns :: |p{0.5\textwidth}|p{0.45\textwidth}|
19
23
20
24
+--------------------------------------+--------------------------------------+
@@ -43,15 +47,23 @@ at its exception handler.
43
47
| | of bounds access in ``__getitem__ ``, |
44
48
| | ``__setitem__ ``, etc.) |
45
49
+--------------------------------------+--------------------------------------+
46
- | :class: `pybind11::value_error ` | ``ValueError `` (used to indicate |
47
- | | wrong value passed in |
48
- | | ``container.remove(...) ``) |
49
- +--------------------------------------+--------------------------------------+
50
50
| :class: `pybind11::key_error ` | ``KeyError `` (used to indicate out |
51
51
| | of bounds access in ``__getitem__ ``, |
52
52
| | ``__setitem__ `` in dict-like |
53
53
| | objects, etc.) |
54
54
+--------------------------------------+--------------------------------------+
55
+ | :class: `pybind11::value_error ` | ``ValueError `` (used to indicate |
56
+ | | wrong value passed in |
57
+ | | ``container.remove(...) ``) |
58
+ +--------------------------------------+--------------------------------------+
59
+ | :class: `pybind11::type_error ` | ``TypeError `` |
60
+ +--------------------------------------+--------------------------------------+
61
+ | :class: `pybind11::buffer_error ` | ``BufferError `` |
62
+ +--------------------------------------+--------------------------------------+
63
+ | :class: `pybind11::import_error ` | ``import_error` |
64
+ +--------------------------------------+--------------------------------------+
65
+ | Any other exception | ``RuntimeError `` |
66
+ +--------------------------------------+--------------------------------------+
55
67
56
68
Exception translation is not bidirectional. That is, *catching * the C++
57
69
exceptions defined above above will not trap exceptions that originate from
0 commit comments