I have the following interface:
public interface ICalculationRule {
public void calculate(EventBag eventBag);
}
and I would like to provide some way to indicate if calculation failed, what would be more correct?
- add
throws Exceptionto method signature - make
calculatemethodboolean(true=success,false– failure)
It all depends on
If during calculation something unexpected happens. It is suppose to throw Exception.
If it is supposed to be handled within use try catch And if caller of your method is suppose to react on that. Then add throws Exception.
If Result NO is something expected to happen and
If error conditions are not of that significance and caller is just interested in knowing the result of sucess or failure. Go for it.
Also don’t go For Generic Exception But be specific.
Also i can think of making delegates to notify caller about success or failure.
I can seek its implementation object by the caller and in calculation method call.
And on success or failure can invoke respective delegate like
hope this guide you to the right dirction 🙂