Catching errors in a embedded script at runtime
Subject: Catching errors in a embedded script at runtime
Newsgroups: gmane.comp.lang.jython.user
Date: 2008-08-21 11:14:23 GMT
My app executes scripts at runtime, taken from files. Each script is in essence a class definition based on an abstract class in my Java. So whatever is in the script, I know it should have a some key methods defined in the abstract base class, and these are called from my java code. I read the script into my interpreter myInterpreter.execfile(scriptStream); and this is void with no exceptions so I cannot really tell at that point if script is OK Then I get a reference for the class PyObject cls = interpreter.get(nameOfMyClass); If cls != null then I think can be reasonably sure it found a valid class in the interpreter namespace I try to instantiate the class PyObject cls_instance = cls.__call__(); Then I convert that into a java object Object o = cls_instance.__tojava__(myAbstractClass.class); If o != Py.NoConversion then I presumably have a usable java object. I then cast o to (myAbstractClass) and I can start treating it as an instance of myAbstractClass and call the base class methods. This works a treat.(Continue reading)
RSS Feed