Reputation: 4503
I currently have a system with the following structure: Website -> WCF -> Database
the WCF portion when called, calls the BLL which in turn calls Entity Framework to get the data it needs and sends back to Website. Currently I have putting my try catch statements in the WCF service, so if any error occurs in Entity Framework or in the BLL the service gets it and throws a FaultException back to the Website. The Website does not to any exception handling, I am using ELMAH so I just get an email with the error and the user is redirected to the error page.
Is this a good place to place the try catch blocks, or should they be in the BLL layer, or website as well? I don't want to handle the errors, just let them get pushed up so the user gets the error page and I get an email with what occurred.
Upvotes: 1
Views: 300
Reputation: 62300
I asked the same question a couple of years back.
Place Try Catch in Business Logic or User Interface
Ideally, if you catch exception in Database layer, you want to throw to UI layer.
In other words, you want to log exception in UI layer. Let UI layer decide whether the exception message need to be displayed to user or just display generic error message.
Upvotes: 2
Reputation: 7009
Exception blocks shouldn't be placed only in a specific tier. Exceptional case may happen in each tier, and each tier may handle if it's capable.
Anyway exceptions should be as "pleasant" as possible to the end user, and it seems that you covered this part good.
Most likely that the BLL tier should catch exceptions, if the Entity Framework code will throw one (which may happen), and there is no "need" to go back all the way to the WCF service (i.e the BLL tier is capable of handling this exception).
Upvotes: 7