I am writing a desktop application that has three layers, where in each layer there is the possibility of Exceptions being occured. Where it is best way to handle an exception if it is raised in a lower layer, such as the data layer or Business Layer? For example, I have the following layers.
Note: I am using Enterprise Library 4.1for exception and logging block, library practice allows me to handle it at any layer, Now question is that at which layer it should be handled.
UI Layer (WinForm) -> Business Layer (BLL) -> Data Layer (DLL).
At Three Layers below are possibilities;
UI layer – Reference(.dll) of BLL is added in this layer.
UI layer exception definitely should be handled at UI layer and should be logged using logging block.
Business LAYER – this is not a web service, these are wrapper function with some business checks. Reference(.dll) of Date Layer is added in this layer.
- One option is that bubble it to UI layer and where it will be handled as others are handled and logged. (Benefit of this option is that I have create only One Exception Configuration as well as one Exception Handler; where as in below case I have to Place Exception Handler at home Common Layer, which will be added in BLL as well as in DLL.)
- Other option is that I logged it at the same level where it is raised and ReThrow it to UI layer where it will be handled as per Exception Policy.
Dater Layer – This layer handles direct database calls using Data Block.
- One option is that bubble it towards end point that is UI layer and where it will be handled as others are handled and logged.
- Other option is that I logged it at the same level where it is raised and ReThrow it to UI layer where it will be handled as per Exception Policy.
Have a good life.