Consider these rules:
rule kickOff
when
then
Inner square1 = new Inner( "inner", "4", "4" );
Outer namedSquare1 = new Outer( "4x4", square1 );
insert( namedSquare1 );
Inner square2 = new Inner( "inner", "5", "5" );
Outer namedSquare2 = new Outer( "5x5", null /* square2 */ );
insert( namedSquare2 );
end
rule innerOuter
dialect "mvel"
when
Outer( inner.length == '4' && name == '4x4' &&
inner.width == '4' )
then
System.out.println( "Hit rule" );
end
and the call for firing all rules:
try {
kSession.fireAllRules();
} catch( RuntimeException e ){
System.out.println( "Caught " + e.getMessage() );
}
This produces the output (with additional printlns before and after):
compiled = 1.020
Caught Exception executing consequence for rule "kickOff" in nested:
java.lang.RuntimeException: cannot invoke getter: getInner
[declr.class: nested.Outer; act.class: nested.Outer] (see trace)
all fired = 0.007
With the try/catch surrounding the call that results in the firing of
rule kickOff where the facts Outer are inserted that cause the
evaluation of the LHS of rule innerOuter where it runs into the
NPE/RuntimeException: you can catch this exception.
-W
On 28/03/2012, scottleff <scott.leff(a)fbfs.com> wrote:
I understand that I cannot expect to catch NPE in my calling java
program.
I
am actually catching java.lang.Exception. I simply continued to call it an
NPE because that was the true issue. My issue can easily be broadened to
apply to any RuntimeException thrown from LHS.
--
View this message in context:
http://drools.46999.n3.nabble.com/NPE-from-LHS-of-rule-is-not-returned-by...
Sent from the Drools: User forum mailing list archive at
Nabble.com.
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users