WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #21  
Old 05-23-2011, 10:00 PM
dcnieho dcnieho is offline
Member
 
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:
Code:
// 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);
    PyList_SET_ITEM(list,0,exc);
    PyList_SET_ITEM(list,1,PyString_FromString(msg));
    return list;
}
I then "raise" my exception by
Code:
data.set( PYTHON_RETURN_OBJECT, PYTHON_EXCEPTION_STRING_LIST(PyExc_RuntimeError,"testing");
at the python end, I wrap all my command() calls in a function errorHandler defined as follows:
Code:
# 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
    else:
        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
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 04:53 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC