Thread: Sdk
View Single Post
Old 05-23-2011, 10:00 PM
dcnieho dcnieho is offline
Join Date: Feb 2011
Posts: 59
Ok, I have a (temporary) solution:

In my C++ code I have defined a helper function modeled after the ones in your viz/python include:
// helper for making the list to communicate an exception
// Returns new reference to list of a python object and a string
inline PyObject* PYTHON_EXCEPTION_STRING_LIST(PyObject* exc, const char * msg)
    PyObject *list = PyList_New(2);
    return list;
I then "raise" my exception by
at the python end, I wrap all my command() calls in a function errorHandler defined as follows:
# function that should be wrapped around any interaction with the stimulus class through command()s
# detect if an error case is communicated, if not, simply pass on the input
def errorHandler(self,input):
    if isinstance(input,list) and issubclass(input[0],BaseException):
        # we have an exception to handle, raise it
        raise input[0](input[1])    # raise exception communicated by C++ code
        return input
This works also if the C++ code doesn't set any return value as in this case command simply returns None (at least that's the input to errorHandler).

I suppose this is dirty and not how its supposed to be done, but tis a workaround for now. Hope you can show me how to get PyErr_SetString to work!
Reply With Quote