I have a three layers C# software : UI, Business, Database.
I have some business rules that I want to implement into my business layer. For instance, if two objects have the same name, the business layer needs to throw an exception to the UI.
My problem is that my application is multi language, and my business layer don’t have access to my resource files. So my UI needs to catch the exception from the business layer, and decide what message it will show to the user.
I was thinking about creating a BusinessException class, with a property who tells the UI which key to take in the ressource file. Do you thing it a good way to do it? Or do you have better ideas? Thank you!
I ended up with a mix of those two solutions. So I’m using only one class : BusinessRuleException. This class as a property “rule” which is a enum of all my business rules.
When my UI receive a BusinessRuleException, it can catch it, and than compare the “rule” to a ressource file and get a friendly message for the user. If the UI can’t find a translation, it will only send the rule as is. So the user still have a change to understand what is going on.
It don’t like the solution of a different exception for every different business rule, because it will end up with so much extra code, which doesn’t help you understand what is the real work you class is doing.