I have a WCF svc separated into a Service Layer, Business Logic Layer and Data Access Layer.
When my DAL encounters an exception, should I catch it there or let it bubble back up to the Service Layer? And why?
Please disregard any client involvement for this scenario, I am only concerned with logging the exceptions on the WCF svc.
It depends also on how you are architecting your solution. For instance, if the DAL and BLL layers are meant to be totally independent components, then they cannot make assumptions about who is calling them. As such, they should both catch exceptions on the component boundary, log those exceptions, then allow the exception to propagate. They may want to wrap the general exception in a layer-specific exception:
catch (Exception ex)
{
Logger.Log(ex);
throw new DalException("Unhandled exception in DAL", ex);
}
If you know these will only be used as part of your overall application, then you can defer logging to the outermost layer - the layer that, if it doesn't catch the exception, the exception won't be logged.