Lines Matching refs:Python
4 Built-in C++ to Python exception translation
7 When Python calls C++ code through pybind11, pybind11 provides a C++ exception handler
8 that will trap C++ exceptions, translate them to the corresponding Python exception,
9 and raise them so that Python code can handle them.
13 Python exceptions. Note that these are not actually Python exceptions, so they
14 cannot be examined using the Python C API. Instead, they are pure C++ objects
15 that pybind11 will translate the corresponding Python exception when they arrive
21 | Exception thrown by C++ | Translated to Python exception type |
66 Python. For that, catch :class:`pybind11::error_already_set`. See :ref:`below
70 :func:`handle::call` when the input arguments cannot be converted to Python
79 a new Python exception using the C++ exception's ``what()`` method, a helper
86 This call creates a Python exception class with the name ``PyExp`` in the given
88 into Python exceptions of type ``PyExp``.
99 The class objects of the built-in Python exceptions are listed in the Python
117 ``PyErr_SetString`` to set a Python exception or ``ex(string)`` to set
120 To declare a custom Python exception type, declare a ``py::exception`` variable
160 translator. Failure to do so will cause Python to crash with ``SystemError:
169 Handling exceptions from Python in C++
172 When C++ calls Python functions, such as in a callback function or when
173 manipulating Python objects, and Python raises an ``Exception``, pybind11
174 converts the Python exception into a C++ exception of type
176 summary and the actual Python exception. ``error_already_set`` is used to
177 propagate Python exception back to Python (or possibly, handle them in C++).
182 | Exception raised in Python | Thrown as C++ exception type |
184 | Any Python ``Exception`` | :class:`pybind11::error_already_set` |
206 Note that C++ to Python exception translation does not apply here, since that is
207 a method for translating C++ exceptions to Python, not vice versa. The error raised
208 from Python is always ``error_already_set``.
225 // py::value_error is a request for pybind11 to raise a Python exception
229 // py::value_error is not a Python exception
237 Handling errors from the Python C API
241 the Python C API directly. When calling the Python C API directly, in
245 After calling the Python C API, if Python returns an error,
247 exception and pass it back to the Python interpreter. This includes calls to
261 Any Python error must be thrown or cleared, or Python/pybind11 will be left in
269 If a Python function invoked from a C++ destructor or any function marked
275 Similarly, Python exceptions raised in a class's ``__del__`` method do not
276 propagate, but are logged by Python as an unraisable error. In Python 3.8+, a
283 pybind11 wrappers around Python exceptions such as
284 :class:`pybind11::value_error` are *not* Python exceptions; they are C++
285 exceptions that pybind11 catches and converts to Python exceptions. Noexcept
287 convert them to Python exceptions and then ``discard_as_unraisable`` as shown
296 // Discard the Python error using Python APIs, using the C++ magic
297 // variable __func__. Python already knows the type and value and of the