From 25894620107f9e8c7f39e903f27608cba9e249a4 Mon Sep 17 00:00:00 2001 From: florent <florent@laas.fr> Date: Thu, 24 Jun 2010 17:27:59 +0200 Subject: [PATCH] Raise a python exception upon c++ exception in plug command * src/dynamic-graph-py.cc. --- src/dynamic-graph-py.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/dynamic-graph-py.cc b/src/dynamic-graph-py.cc index 01f6963..54a4eb1 100644 --- a/src/dynamic-graph-py.cc +++ b/src/dynamic-graph-py.cc @@ -10,6 +10,8 @@ #include <dynamic-graph/interpreter.h> +static PyObject* error; + static dynamicgraph::Interpreter interpreter; static PyObject* @@ -24,7 +26,12 @@ plug(PyObject* self, PyObject* args) std::ostringstream os; ss << std::string(out) << " " << std::string(in); std::istringstream cmdArg(ss.str()); - interpreter.cmdPlug(std::string("plug"), cmdArg, os); + try { + interpreter.cmdPlug(std::string("plug"), cmdArg, os); + } catch (dynamicgraph::ExceptionFactory& exc) { + PyErr_SetString(error, exc.getStringMessage().c_str()); + return NULL; + } return Py_BuildValue(""); } @@ -46,4 +53,8 @@ initwrap(void) m = Py_InitModule("wrap", sotTutorialMethods); if (m == NULL) return; + + error = PyErr_NewException("dynamic_graph.wrap.error", NULL, NULL); + Py_INCREF(error); + PyModule_AddObject(m, "error", error); } -- GitLab