py::builtins::raise

Defined in <pypp/builtins/raise.hpp>

template <class type>
[[noreturn]] constexpr void raise(type&& exception);        // 1

template <class type>
[[noreturn]] constexpr void raise(type& exception);         // 2

template <class type>
[[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

#include <pypp/builtins/raise.hpp>
#include <pypp/builtins/print.hpp>

int main()
{
    try
    {
        py::raise(py::BaseException("example exception"));
    }
    catch (py::BaseException& exception)
    {
        py::print("exception handled successfully:", exception);
    }
}

Output:

exception handled successfully: example exception