diff --git a/docs/advanced/exceptions.rst b/docs/advanced/exceptions.rst index 874af4cc4..a96f8e8f4 100644 --- a/docs/advanced/exceptions.rst +++ b/docs/advanced/exceptions.rst @@ -80,7 +80,7 @@ module and automatically converts any encountered exceptions of type ``CppExp`` into Python exceptions of type ``PyExp``. It is possible to specify base class for the exception using the third -parameter, a pointer to `PyObject`: +parameter, a `handle`: .. code-block:: cpp diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 3185d4bd7..af5d9f503 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -1868,10 +1868,10 @@ template class exception : public object { public: exception() = default; - exception(handle scope, const char *name, PyObject *base = PyExc_Exception) { + exception(handle scope, const char *name, handle base = PyExc_Exception) { std::string full_name = scope.attr("__name__").cast() + std::string(".") + name; - m_ptr = PyErr_NewException(const_cast(full_name.c_str()), base, NULL); + m_ptr = PyErr_NewException(const_cast(full_name.c_str()), base.ptr(), NULL); if (hasattr(scope, name)) pybind11_fail("Error during initialization: multiple incompatible " "definitions with name \"" + std::string(name) + "\""); @@ -1901,7 +1901,7 @@ PYBIND11_NAMESPACE_END(detail) template exception ®ister_exception(handle scope, const char *name, - PyObject *base = PyExc_Exception) { + handle base = PyExc_Exception) { auto &ex = detail::get_exception_object(); if (!ex) ex = exception(scope, name, base);