On Mar 1, 2007, at 4:01 PM, Mrinal Khanvilkar wrote:

Hi,

Does anyone know how to catch exceptions in a RULE .
I mean like

(defrule someRule
    "comment"
    (Callhome (thing1 ?a)(thing2 ?b))
    (try (< ?a ?b)catch (printout t "they need to be integers" crlf))
    (test(eq ?b TRUE))
    =>
        (printout t "done" crlf)
        )

in the above case the engine throws me an exception when ?a and ?b happen to be strings and then it doesnt fire the remaining rules. i dont want that. Instead i would want the engine to just ignore this rule if ?a ?b are strings.
can this be done.?


You'd have to put that "try" statement into a "test" conditional element, just like any other function call that's outside a pattern. Just make sure you return FALSE from the catch block, and it will halt pattern matching. Just something like

(test (try
        (< ?a ?b)
      catch
        (printout t "they need to be integers" crlf)
        FALSE))

ought to work fine.





---------------------------------------------------------
Ernest Friedman-Hill
Advanced Software Research          Phone: (925) 294-2154
Sandia National Labs                FAX:   (925) 294-2234
PO Box 969, MS 9012                 [EMAIL PROTECTED]
Livermore, CA 94550                 http://www.jessrules.com

--------------------------------------------------------------------
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