I am just looking for a little best-practice advice.
I have a service, "price sheet service" where by a user can save a price sheet of some sort.
There are a few instances or configurations that can leave inconsistent data, and in those events I want to end the function execution.
An example would be if the customerId wasn't set on the object, or the salesperson's userId couldn't be found in the database.
My question is what is the best way to leave a function when you encounter a business logic error?
I like the way Exceptions stop execution right there and allow you to re-throw the Exception. The problem with that is, I've have heard exceptions aren't to be used for flow control.
Currently I just have a bunch of nested if/elses whereby I don't commit my transaction unless the local variable of $service_error_message
hasn't been set.
If $service_error_message
is null then I know none of my validators have failed and it is okay to save.
Does anyone have a suggestion for how to better handle these scenarios?