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 throw;
{
rule.Execute(context);
}
catch (Exception ex)
{
context.AddErrorResult(string.Format("{0}:{1}", rule.RuleName, ex.Message));
if (rule.IsAsync)
context.Complete();
}
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.
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?
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
Ok, I think about to create my own CSLA version.
Copyright (c) Marimer LLC