Boost.Python add bindings to existing PyObject (for exception handling)
<p>In order to expose a C++ exception to Python in a way that actually works, you have to write something like:</p>

<pre><code>std::string scope = py::extract&lt;std::string&gt;(py::scope().attr("__name__"));
std::string full_name = scope + "." + name;
PyObject* exc_type = PyErr_NewException(&amp;full_name[0], PyExc_RuntimeError, 0);
// ...
</code></pre>

<p>But this doesn't seem to interract with anything else in Boost.Python. If I want to expose:</p>

<pre><code>struct Error { int code; };
</code></pre>

<p>I could write:</p>

<pre><code>py::class_&lt;Error&gt;("Error", py::no_init)
    .def_readonly("code", &amp;Error::code)
;
</code></pre>

<p>How can I combine the class binding for <code>Error</code> with the exception creation on <code>PyErr_NewException</code>? Basically, I want to <code>throw Error{42}</code> and have that work in the obvious way from Python : I can catch by <code>Error</code> or <code>RuntimeError</code> and have that work, and I can catch by <code>AssertionError</code> (or similar) and have that neither catch the <code>Error</code> nor throw a <code>SystemError</code>. </p>