My code is throwing an exception in the If.java class.

The reason is : the updateDB-my-fact returns null, which is not allowed in
the "if" function.

As "if" is a function, it searchs for the "else" function in its parameters.
Of couse, as my function returns null, Jess can't compare it with "else", so
I obtain an exception.

Of course, my function could have returned a Value, but as far as it just
set a flag, it didn't. And it works well in the RHS part of other rules, so
this is a special case.

Guideline : a user-defined function MUST return a Value in order to be used
in a "if" expression.

Emmanuel Lecharny, IKTEK
06 08 33 32 61, www.iktek.com <http://www.iktek.com>


-----Message d'origine-----
De : [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]De
la part de [EMAIL PROTECTED]
Envoye : vendredi 11 mai 2001 13:24
A : =?iso-8859-1?Q?Emmanuel_L=E9charny?=
Cc : [EMAIL PROTECTED]
Objet : Re: JESS: Problem with "if" and multiple expressions with user
function call


The exception message "Error during execution" is what the
Funcall.execute() method says when a called Java function throws an
exception. In this case, the stack trace you get from catching the
JessException and printing it out isn't necessarily the most
informative one -- you want the exception object thrown by the Java
method. That exception, thrown by your Java function, would most
likely tell you what the problem is. So, when you write Java code to
work with Jess, you should handle JessExceptions something like this:


                } catch (JessException re) {
                    if (re.getNextException() != null) {
                        System.out.println(re.toString());
                        System.out.print("\nNested exception is:\n");

System.out.print.println(re.getNextException().getMessage());
                        re.getNextException().printStackTrace(System.out);

                    } else
                        re.printStackTrace(m_rete.getErrStream());

If you make these changes, you'll probably find out right away what is
going wrong.



I think =?iso-8859-1?Q?Emmanuel_L=E9charny?= wrote:
[Charset iso-8859-1 unsupported, filtering to ASCII...]
> Hi,
>
> I have a problem when I use a multiple expression, in which I call a user
> function in a if-then-else statement :
>
> ... (rule)
> ?my-fact <- (STUFF (value ?value))
>                   (CONTROL (current-value ?cv) (maximum ?max))
> =>
>  (bind ?new-value (+ ?cv ?value)
>  (if (>= ?new-value ?max)
>   then
>    (modify ?my-fact (state 4) (value ?new-value))
>    (updateDB-my-fact ?my-fact-id 4 ?new-value)
>   else
>    (modify ?my-fact (state 2) (value ?new-value))
>    (updateDB-my-fact ?my-fact-id 2 ?new-value)
>  )
>
> This is what I get (I don't know if I deserve it ;) :
>
> Jess reported an error in routine Funcall.execute
>         while executing (if (>= ?new-value ?max) then (modify-n ?my-fact
> <External-Address:[I> 4 <External-Address:[I> ?new-value)
> (updateDB-my-fact ?my-fact-id 4 ?new-value) else (modify-n ?my-fact
> <External-Address:[I> 2 <External-Address:[I>
>  ?new-value) (updateDB-my-fact ?my-fact-id 2 ?new-value))
>         while executing defrule my-rule.
>   Message: Error during execution.
>         at java.lang.Throwable.<init>(Throwable.java:84)
>         at java.lang.Exception.<init>(Exception.java:35)
>         at jess.JessException.<init>(JessException.java:53)
>         at jess.Funcall.execute(Funcall.java:254)
>         at jess.Defrule.fire(Defrule.java:205)
>         at jess.Activation.fire(Activation.java:65)
>         at jess.Agenda.run(Agenda.java:126)
>         at jess.Agenda.run(Agenda.java:102)
>         at jess.Rete.run(Rete.java:752)
>         at com.Motor.treatMyStuff(Moteur.java:340)
>         at java.lang.reflect.Method.invoke(Native Method)
>         at
> sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:242)
>         at sun.rmi.transport.Transport$1.run(Transport.java:155)
>         at java.security.AccessController.doPrivileged(Native Method)
>         at sun.rmi.transport.Transport.serviceCall(Transport.java:152)
>         at
> sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:462)
>         at
>
sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:6
> 62)
>         at java.lang.Thread.run(Thread.java:498)
>
> updateDB-my-fact is a Java function, which work perfectly well if I call
it
> outside the then or else part. A workaround I found is something like :
>
> ...
>  (if (>= ?new-value ?max)
>   then
>    (modify ?my-fact (state 4) (value ?new-value))
>    (bind ?new-state 4)
>   else
>    (modify ?my-fact (state 2) (value ?new-value))
>    (bind ?new-state 2)
>  )
>
> (updateDB-my-fact ?my-fact-id ?new-state ?new-value)
> ...
>
> which works well.
>
> Emmanuel L_charny, IKTEK
> 06 08 33 32 61, www.iktek.com
>



---------------------------------------------------------
Ernest Friedman-Hill
Distributed Systems Research        Phone: (925) 294-2154
Sandia National Labs                FAX:   (925) 294-2234
Org. 8920, MS 9012                  [EMAIL PROTECTED]
PO Box 969                  http://herzberg.ca.sandia.gov
Livermore, CA 94550

---------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the
list (use your own address!) List problems? Notify
[EMAIL PROTECTED]
---------------------------------------------------------------------


---------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the
list (use your own address!) List problems? Notify [EMAIL PROTECTED]
---------------------------------------------------------------------

Reply via email to