Commit 7e5e1ce4 authored by Florent Lamiraux's avatar Florent Lamiraux Committed by Florent Lamiraux florent@laas.fr
Browse files

Catch exceptions in getValue of signal-base-py.cc

    Throwing an exception in the C/Python API makes the python interpreter
    terminate. The correct way is to catch C++ exception and to raise python
    errors with the same message.
parent 8fc08b88
......@@ -154,28 +154,35 @@ namespace dynamicgraph {
pointer = PyCObject_AsVoidPtr(object);
SignalBase<int>* signal = (SignalBase<int>*)pointer;
/* Temptative for specific signal type. */
Signal<dynamicgraph::Vector,int> * sigvec
= dynamic_cast< Signal<dynamicgraph::Vector,int>* >( signal );
if( NULL!= sigvec )
{
return vectorToPython( sigvec->accessCopy() );
}
Signal<dynamicgraph::Matrix,int> * sigmat
= dynamic_cast< Signal<dynamicgraph::Matrix,int>* >( signal );
if( NULL!= sigmat )
{
return matrixToPython( sigmat->accessCopy() );
}
Signal<double,int> * sigdouble
= dynamic_cast< Signal<double,int>* >( signal );
if( NULL!= sigdouble )
{
return Py_BuildValue("d", sigdouble->accessCopy() );
}
try {
/* Temptative for specific signal type. */
Signal<dynamicgraph::Vector,int> * sigvec
= dynamic_cast< Signal<dynamicgraph::Vector,int>* >( signal );
if( NULL!= sigvec )
{
return vectorToPython( sigvec->accessCopy() );
}
Signal<dynamicgraph::Matrix,int> * sigmat
= dynamic_cast< Signal<dynamicgraph::Matrix,int>* >( signal );
if( NULL!= sigmat )
{
return matrixToPython( sigmat->accessCopy() );
}
Signal<double,int> * sigdouble
= dynamic_cast< Signal<double,int>* >( signal );
if( NULL!= sigdouble )
{
return Py_BuildValue("d", sigdouble->accessCopy() );
}
} catch (const std::exception& exc) {
PyErr_SetString(dgpyError, exc.what());
return NULL;
} catch (...) {
PyErr_SetString(dgpyError, "Unknown exception");
return NULL;
}
/* Non specific signal: use a generic way. */
std::ostringstream value;
try {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment