.. index:: py::builtins::raise .. _doxycast_pypp_namespacepy_1_1builtins_1aeab1ec7c7383be198756a6bc0036ecfb: .. _py-builtins-raise: *py::builtins::*\ raise ======================= *Defined in* ```` .. code-block:: cpp template [[noreturn]] constexpr void raise(type&& exception); // 1 template [[noreturn]] constexpr void raise(type& exception); // 2 template [[noreturn]] constexpr void raise(const type& exception); // 3 Throws or raises an exception. Template parameters ------------------- ``type``: The type of exception. Parameters ---------- ``exception``: Exception object to raise. Example ------- .. code-block:: cpp #include #include int main() { try { py::raise(py::BaseException("example exception")); } catch (py::BaseException& exception) { py::print("exception handled successfully:", exception); } } **Output**: .. code-block:: text exception handled successfully: example exception