py::builtins::BaseException::what

virtual const char* what() const noexcept override;     // 1

Returns the explanatory string.

Return value

The explanatory string.

Example

#include <pypp/builtins.hpp>

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

Output:

exception handled successfully: example exception