Thanks for the help and quick response. I got it to work. :)


For getting the error message, the relevant code is:

catch (PyException excp) {
            excp.normalize();
            PyObject filename = excp.value.__findattr__("
filename"); //not needed in my case
            PyObject lineno = excp.value.__findattr__("lineno");
            PyObject offset = excp.value.__findattr__("offset");
            PyObject message = excp.value.__findattr__("msg");
}


To get the list of all fields, I had to do the following.

PythonInterpreter interp = new PythonInterpreter();
interp.exec(sourceCode.toString());
PyStringMap keyValueMap = (PyStringMap)interp.getLocals();
PyIterator keyValueSet = (PyIterator)keyValueMap.iteritems();
for (Object temp : keyValueSet) {
    PyTuple tempEntry = (PyTuple)temp;
    Iterator iter = tempEntry.iterator();
    System.out.println(iter.next() + " = " + iter.next() + "\n");
}

It works, but somehow I do not feel very confident about the second code (getting the list of all fields). I am doing too many casts (possibility of classCastException) and am always assuming that PyTuple only has two elements in it.

I can put checks to make sure that my assumptions are correct. But, in case my assumptions are invalid, all I can do is print error messages.

Do you guys think, the second code above is reliable? Is it the recommended way to get all the locals and their values?