Thanks for your feedback Ram�n, though maybe I didn't explain my problem
correctly. The issue I am having is not so much throwing the customised
exception as throwing it from a method invocation that does not explicitly
return a status code (and in the java stub projection a CacheException). For
example, I have an object script web method with the following signature:

ClassMethod ReadCustomer(id As %Integer) As cls.Customer

This signature looks as follows in the Java Projection which is generated:
public static cls.Customer ReadCustomer (Database _db, java.lang.Integer id)
throws CacheException

My basic question is, how do I throw an exception from within the
ReadCustomer object script code that will be caught in the Java proxy class
as a CacheException?

If I try: quit $$$ERROR($$$InvalidID) from within this code I get a general
Java index out of bound exception. Note that the variable $$$InvalidID is a
user defined status code which I imported into my namespace using XML files
and the %Library.MessageDictionary class. The XML looks like:
<MsgFile Language="en">

<MsgDomain Domain="UserErrors">

<Message Id="-20101" Name="InvalidID">ID does not exist.</Message>

<Message Id="-20102" Name="SaveError">The form was not saved because of the
following error(s).</Message>

<Message Id="-20103" Name="SaveCorrect"> Please correct these error(s) and
try again.</Message>

</MsgDomain>

</MsgFile>

I don't believe the problem is with the custom status code as if I invoke
the following object script method:

ClassMethod CallError() As %Status
{
 quit $$$ERROR($$$InvalidID)
}

from the java test client I spoke of in my original mail, a CacheException
is thrown instantly and the java catch block is executed in the client. I
can then parse the error as follows:
catch (CacheException ex) {

System.out.println( "Caught Cache exception: " + ex.getClass().getName() +
": " + ex.getMessage() );

ex.printFullTrace(System.out);

Output:

C:\Java Projection Tests\ReturnStatusDirectly>java CallError
Caught Cache exception: com.intersys.objects.CacheException: ERROR
<UserErrors>-
20101: ID does not exist.

Apart from this if I use the GeneralError instead of my custom defined one I
get the same behaviour i.e. (quit $$$ERROR($$$GeneralError,"ID is not
valid")).
What I am trying to do is get to this point from within the ReadCustomer
method but calling the 'CallError' method (or any method that returns a
%Status) from within the ReadCustomer method does not work .

Your response seems to focus on the 'customised' aspect of the error
messages - as you can see I am not trying to define my own Java exception
types just the content of the message contained within the 'CacheException'
itself which seems to be working fine. I think what I am missing is
something more fundamental that that. Should I be looking to use ETRAP,
ZTRAP, introduce error handlers etc...?  I don't believe that I am
'throwing' the Cache exceptions correctly i.e. using quit
$$$ERROR($$$InvalidID).

Thanks in advance for any help.

Regards,
Michelle.

"Ram�n Jim�nez" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Michelle
>
> Not sure you can control the kind of exceptions thrown by the Java
> binding, but...
>
> > As a test I wrote another client that invokes a class method using java
> > projections that returns a status explicitly and this works fine - i.e.
> > throws a CacheException on the 'quit'.
>
> Would it make sense to introduce another class/method in the call
> sequence, which catches the CacheException if it occurs and re-throws
> the customized exception you're interested in?
>
> HTH,
>
> Ram�n
>
> -- 
> ZCacheLib - Open Source Extensions for Cach�
> http://www.zcachelib.org



Reply via email to