<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
ok I have added a ConsequenceExceptionHandler to RuleBaseConfiguration,
default just wraps and re-throws as a runtime exception. You can
override this to provide a custom consequence exception handler. But do
be aware that if you swallow the working memory integrity may be
invalid, if the error happened during a working memory action.<br>
<br>
Mark<br>
Anstis, Michael (M.) wrote:
<blockquote
 cite="mid:6CE83AFC8500B641AE00AC1674A3B4AC037EF6F8@eu1wam08.warley.ford.com"
 type="cite">
  <meta http-equiv="Content-Type" content="text/html; ">
  <meta content="MSHTML 6.00.2900.2873" name="GENERATOR">
  <div dir="ltr" align="left"><span class="801413315-24082007"><font
 color="#0000ff" face="Arial" size="2">For what it's worth I think this
would be a good idea too.</font></span></div>
  <div dir="ltr" align="left"><span class="801413315-24082007"></span>&nbsp;</div>
  <div dir="ltr" align="left"><span class="801413315-24082007"><font
 color="#0000ff" face="Arial" size="2">Perhaps the default ASM wrapper
around the RHS could use a try...catch block and log any exceptions of
a rules' activation in a (drools) accessible log? Heck you could even
allow certain accepted exceptions to be defined as a property of the
rule; and any other non-defined exception types cause the session to
become invalidated. If we're ever to let "the business" define rules we
need to accept they might make mistakes that we're better off capturing
and report back than invalidate the whole session. </font></span><span
 class="801413315-24082007"><font color="#0000ff" face="Arial" size="2">Why
should a whole session be invalidated because a single rule activation
failed anyway?</font></span></div>
  <div dir="ltr" align="left"><span class="801413315-24082007"></span>&nbsp;</div>
  <div dir="ltr" align="left"><span class="801413315-24082007"><font
 color="#0000ff" face="Arial" size="2">With kind regards,</font></span></div>
  <div dir="ltr" align="left"><span class="801413315-24082007"></span>&nbsp;</div>
  <div dir="ltr" align="left"><span class="801413315-24082007"><font
 color="#0000ff" face="Arial" size="2">Mike</font>&nbsp;</span></div>
  <br>
  <blockquote style="margin-right: 0px;">
    <div class="OutlookMessageHeader" dir="ltr" align="left"
 lang="en-us">
    <hr tabindex="-1"> <font face="Tahoma" size="2"><b>From:</b>
<a class="moz-txt-link-abbreviated" href="mailto:rules-users-bounces@lists.jboss.org">rules-users-bounces@lists.jboss.org</a>
[<a class="moz-txt-link-freetext" href="mailto:rules-users-bounces@lists.jboss.org">mailto:rules-users-bounces@lists.jboss.org</a>] <b>On Behalf Of </b>Yang
Song<br>
    <b>Sent:</b> 24 August 2007 16:16<br>
    <b>To:</b> Rules Users List<br>
    <b>Subject:</b> Re: [rules-users] How to catch Exceptions when
firing rules<br>
    </font><br>
    </div>
    <div>Thanks a lot for the answer, Mark. But I don't think it makes
sense. </div>
    <div>&nbsp;</div>
    <div>Because in some scenarios, you cannot guarantee the
consequence part of rule is 100% correct -- there could be errors
happening in run-time which are hard to predict, especially when a
complex action or logic will be executed as the concequece. </div>
    <div>&nbsp;</div>
    <div>There should at least be some mechanisms to tell whoever fires
the rule that there is something wrong during the rule firing process,
then and he&nbsp;can&nbsp;do something, e.g. create a new session. Also it should
enable the&nbsp;rule firer&nbsp;to catch these exceptions and do the clean up
work silently -- instead of leaving these things on the stderr even
cannot be seen in the logs. This will make the program depending on the
JBoss Rules to be more robust. </div>
    <div>&nbsp;</div>
    <div>What do you think? If JBoss Rules already has the ability to
do this job, can you please let me know?</div>
    <div>&nbsp;</div>
    <div>Thanks again,</div>
    <div>Yang<br>
    <br>
&nbsp;</div>
    <div><span class="gmail_quote">On 8/24/07, <b
 class="gmail_sendername">Mark Proctor</b> &lt;<a moz-do-not-send="true"
 href="mailto:mproctor@codehaus.org">mproctor@codehaus.org</a>&gt;
wrote:</span>
    <blockquote class="gmail_quote"
 style="border-left: 1px solid rgb(204, 204, 204); margin: 0px 0px 0px 0.8ex; padding-left: 1ex;">
      <div bgcolor="#ffffff" text="#000000">Once an exception is thrown
on a conseuqence the current session is considered invalid. You'll need
to add the try catch inside of the actual consequence.<br>
      <br>
Mark<br>
Yang Song wrote:
      <blockquote type="cite">
        <div><span class="e" id="q_114978d8fa9e2dee_1">
        <div>Hi, </div>
        <div>&nbsp;</div>
        <div>Anyone knows how to catch the exception when firing the
rules? </div>
        <div>&nbsp;</div>
        <div>I wrapped the session.fireAllRules() method using
try...catch, however it doesn't work: when someone wrote&nbsp;bad code in
the rule's action part, the Exception will be thrown and printed to the
stderr, and this will make the rule engine stop working --&nbsp;the
try...catch outside doesn't help anything. </div>
        <div>&nbsp;</div>
        <div>If&nbsp;&nbsp;the exception&nbsp;thrown from&nbsp;the rule's action part&nbsp;can
be caught externally,&nbsp;the system can be protected from interrupting
Exception.</div>
        <div>
        <p><font style="background-color: rgb(255, 255, 255);"
 color="#3333ff" face="courier new,monospace">try {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _log.debug("Firing rules in : " + getName());</font></p>
        <p><font style="background-color: rgb(255, 255, 255);"
 color="#3333ff" face="courier new,monospace">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
session.fireAllRules();</font></p>
        <p><font style="background-color: rgb(255, 255, 255);"
 color="#3333ff" face="courier new,monospace">} catch (Exception e) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; _log.info("Error when firing rules: ", e);<br>
}</font> <br>
        </p>
        <p>Thanks, <br>
Yang</p>
        </div>
        </span></div>
        <pre><hr size="4" width="90%">
_______________________________________________
rules-users mailing list
<a moz-do-not-send="true"
 onclick="return top.js.OpenExtLink(window,event,this)"
 href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a>
<a moz-do-not-send="true"
 onclick="return top.js.OpenExtLink(window,event,this)"
 href="https://lists.jboss.org/mailman/listinfo/rules-users"
 target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a>
  </pre>
      </blockquote>
      <br>
&nbsp;</div>
      <br>
_______________________________________________<br>
rules-users mailing list<br>
      <a moz-do-not-send="true"
 onclick="return top.js.OpenExtLink(window,event,this)"
 href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org </a><br>
      <a moz-do-not-send="true"
 onclick="return top.js.OpenExtLink(window,event,this)"
 href="https://lists.jboss.org/mailman/listinfo/rules-users"
 target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
      <br>
    </blockquote>
    </div>
    <br>
  </blockquote>
  <pre wrap="">
<hr size="4" width="90%">
_______________________________________________
rules-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a>
  </pre>
</blockquote>
<br>
</body>
</html>