Business Logic – Representing Business Rules with Exceptions

business-logicbusiness-rulesidiomsrules-and-constraints

I know it is expensive but (IMO) I believe it is a very good practice. I'm talking about rules like say, you can't save an Invoice if you are not a sales person… so in that case throwing an exception saying 'your are not authorized' or such…

Another approach it would be having objects with a status or something like that

Is there any other approach? how do you feel about it?

Best Answer

If you mean representing individual business rule checks with exceptions, then I don't think it's a very good idea. Many times you have to report more than one failed condition, and not stop on the first one.

On the other hand, I do believe that checking for all rules and then throwing an exception with the summary is a good practice.

Related Topic