Re: [tcljava-user] How to use Interp.setResult?
Brought to you by:
mdejong
From: Mo D. <mo...@mo...> - 2009-04-14 18:02:19
|
Bret Comstock Waldow wrote: > Hello, > > I have not found good documentation for some of Jacl - the API docs on > the tcljava.sourceforge.net site are not giving me a good enough > understanding to determine how to solve an exception. > > I have a command-line java program. In it's primary class constructor, > it creates a TCL Interp session with the name of an external script > file, and exits when the Interp session is complete. In response to > various commands found in a script, various Java objects are created, > and methods called on those objects from the script. I have a number of > working examples of this, including some that successfully return values > to the Interp session for further processing. > > But I haven't figured out what Interp.setResult() does, and it looks as > if it might be useful. The setResult() method sets the "result" pointer in a Jacl interpreter to a specific TclObject. It is typically used from a Java implementation of a Tcl method to indicate the result of a Tcl command. If you have a Java method, it is better to just have it return a Java result and then invoke the method with the java::call command or from a class instance handle (like java0x1, a result object from a java::new command). > TCL: > $tableName getEntry $column $row > > Java: > /** > * *@return* int - The number of columns in this result set. > */ > *public* *int* getColumnCount() > { > log.debug( "getColumnCount - columnCount is " + columnCount ); > *return* columnCount; > } > > *public* *void* getEntry( String columnName, *int* currentRow ) > *throws* TclException > { > log.debug( "getEntry - column name is " + columnName ); > myInterp.setResult( "an Answer" ); > } > > > tcl.lang.ReflectException > at tcl.lang.JavaInvoke.call(JavaInvoke.java:328) > at tcl.lang.JavaInvoke.callMethod(JavaInvoke.java:161) > at tcl.lang.ReflectObject.cmdProc(ReflectObject.java:916) > It is not clear what if going on from this example code and stack trace. Typically, the ReflectException means there was some error in the Java code and it got wrapped into a ReflectException when moving from Java back to tcl. When Jacl hits a ReflectException, it saves the original Java exception object and a description string are saved in the global variable named "errorCode". Printing out a stace trace of the Java exception found there would likely be a good place to start. Mo DeJong |