Search code examples
asp.netexceptionbusiness-logic-layerservice-layer

Business Layer errors and Service Layer handling - Best way?


We're building a large web app that has numerous layers. In order to communicate to the business layer we're using a service layer that the web layer calls when data is needed. Unfortunately, it seems that if exceptions are thrown in the business layer, it seems that the services on the web side are wrapping the exceptions and re-throwing them. We're looking for a clear way to encapsulate the error and log it, without WCF wrapping a new exception around the original.

Thanks


Solution

  • FWIW, each of our exposed WCF Service Layer methods catches a System.Exception and passes it off to a HandleException helper (this could also be a base service class method I guess)

    HandleException:

    1. Logs the error
    2. Applies the exception reformatting to SOAP faults (currently we are using WCF Exception Shielding)
    3. Applies any exception-specific handling (of the format if (ex is SomeTypeOfException) ...)