Ram�n, Thanks yet again for this information. I have been testing using this approach since your last posting i.e. setting $ECODE and indeed attempting to get a readable message into the $ZERROR variable at the same time, but as you have stated all I get is the <ECODETRAP> string also. I was trying to find a way to set this myself but if there is a way to pick out the string from the $ECODE information then it should be OK. I will continue to work on this approach.
Much appreciated, Michelle. "Ram�n Jim�nez" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > Michelle, > > Certainly Cach� lacks a proper exception mechanism. However the typical > way in which you force a runtime error is to set a value to the $ECODE > variable. Within Cach�, this would attempt to execute an error trap if > it's set, otherwise it would stop the current process. > > When you use this functionality within a method from the Java > projection, the exception CacheServerException is thrown and you could > catch that. > > Note that, since control is interrupted, it may be a good idea to clean > up within the Cach� method before setting the $Ecode value. In Java we > usually do that via a catch or a finally block, but neither of those > exist in Cach� and since control is transferred back to the Java side > when the error occurs, it's better to clean up any resources (e.g. > release locks, close objects) before "throwing" the error. > > I've put together a very contrived example to reproduce this behaviour - > simply cut'n-paste the Cach� class below and put the Java main() method > in the same class or in another to test the example. > > The main problem I see with this approach is that Cach� will return > "<ECODETRAP>" as the error code for the operation - what typically > happens in the Cach� side is that you set $Ecode to a descriptive > message, then within your error trap if $ZERROR contains "<ECODETRAP" > you can pick the message from $Ecode. However in my tests the > getMessage() method of the thrown CacheServerException only contains the > "cryptic" <ECODETRAP> string. I will look into it within Eclipse later > to see if it's possible to get more information from it. > > HTH, > > Ram�n > ----------------------------------------------------------------- > > Class Test.JavaEx Extends %RegisteredObject [ ProcedureBlock ] > { > Projection prj As %Projection.Java; > > Method CreateResultSet(dummy As %Integer) As %Library.ResultSet > { > Set result = ##class(%Library.ResultSet).%New() > Set $Ecode = "Forced exception" > Quit result > } > } > > ----------------------------------------------------------------- > public static void main( String[] args ) throws Exception { > Database conn = CacheDatabase.getDatabase( > "jdbc:Cache://localhost:1972/USER" ); > JavaEx ex = new JavaEx( conn ); > ex.CreateResultSet( new Integer( 0 ) ); > conn.close(); > }
