Bug? Csla.Rules.BusinessRules.RunRules() hides Exceptions in rules

Bug? Csla.Rules.BusinessRules.RunRules() hides Exceptions in rules

Old forum URL: forums.lhotka.net/forums/t/11787.aspx


Holger posted on Tuesday, January 15, 2013

We log all unhandeled exceptions for monitoring. I have a case where an exception occurs in the business rule execute-method. We can not monitor those exception, because the BusinessRules-class does not rethrow.

There is a try-catch block in Csla.Rules.BusinessRules.RunRules() method which hides exceptions on rule execution. 

Is it possible to fix this and rethrow this exception?

try
{
   rule.Execute(context);
}
catch (Exception ex)
{
   context.AddErrorResult(string.Format("{0}:{1}", rule.RuleName, ex.Message));
   if (rule.IsAsync)
     context.Complete();

   throw;
}

 

 

JonnyBee replied on Thursday, January 17, 2013

An unhandled exception in a rules Execute method will be added as a broken rule to that property/object. 

We cannot allow unhandled exception in rules to be thrown as you suggest as this would stop the entire rule processing and leave the object in an indetermined state. 

Holger replied on Thursday, January 17, 2013

Is it possible to add a setting in app.config, so that the user of the csla-framwork can decide to rethrow exceptions in rules or not?

JonnyBee replied on Thursday, January 17, 2013

No, the only solution will require extending the rules framework to accept a custom exception logger - which is not supported at the time.

CSLA can not rethrow the exception - the rule subsystem MUST make sure to check all rules and not leave the object in an undetermined state and you may get more than one exception. Remenber also to handle a combination of sync and async rules.

Your only option - right now - is to edit the CSLA source locally to create your own CSLA version and add exception logging in BusinessRules.RunRules

Holger replied on Wednesday, January 23, 2013

Ok, I think about to create my own CSLA version.

Copyright (c) Marimer LLC