Today I would like to discuss a bit on the best practices for handling Exceptions in Enterprise applications where in WCF Service is used at the business layer
Ideally any standard Enterprise application will have 3 layers – Presentation, Business and Data Access.
Predominantly the WCF role will come in to play at Business layer (where in the real business rules are defined/ elicited).
So as a best practice it would be good if you follow these thumb rule at each layer to ensure the smoother operations or flow
Identify & Define the Type of exception which you want to handle at the business layer
For ex : MyException
Public class MyException
Describe/Collect the details which you want to handle.
Decorate the method/operation with the identified exceptions – Define FaultContract’s for the Operations
Public interfact IMyService
Rule 3:Throw the FaultException
For ex :
At the configuration side – Enable Exception propagation
At the Presentation layer catch the respective exception which you are throwing from the Business layer.