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 开发者_如何学Pythonexceptions 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
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:
- Logs the error
- Applies the exception reformatting to SOAP faults (currently we are using WCF Exception Shielding)
- Applies any exception-specific handling (of the format
if (ex is SomeTypeOfException)
...)
There are various ways to do this. The solution you presented isn't half bad I believe, though it doesn't scale much (mixing business specific error handling with web-related code creates some sort of coupling). All this depends on your achitecture: you could add a superficial, lightweight layer that translates business errors into web errors, that are handled in the web layer error handling code. You could also you AoP and intercept the calls and translate the errors for the layers above.
精彩评论