in src/exceptions.cc [143:164]
void export_exceptions(py::module_& m) {
static py::exception<PulsarException> base{m, "PulsarException"};
static auto exceptions = createPythonExceptionMap(m, base);
py::register_exception_translator([](std::exception_ptr e) {
try {
if (e) {
std::rethrow_exception(e);
}
} catch (const PulsarException& e) {
auto it = exceptions.find(e._result);
if (it != exceptions.end()) {
PyErr_SetString(it->second.ptr(), e.what());
} else {
base(e.what());
}
} catch (const std::invalid_argument& e) {
PyErr_SetString(PyExc_ValueError, e.what());
} catch (const std::exception& e) {
PyErr_SetString(PyExc_RuntimeError, e.what());
}
});
}