views:

39

answers:

2

I've an application that offers its Business Layer through a Service Layer developed with WCF. What I'm thinking about is: this service layer offers operational method like Create, Update and so on. These operation then reroute these calls to the Business Layer. The question is: suppose that one of these call doesn't accept a null input value (like: Create a null object), where is the best place to perform the check? My personal answer is in both the places (service and business) as I can guarantee the reuse of the Business Layer without using the Service Layer and viceversa.

Am I right?

Thanks Marco

A: 

if you dont handle the error in the DAL or BLL, then it bubbles up until you catch it. Exceptions do not get "overwritten".

If you handled it in the DAL then you no longer have an exception. If you didnt fully handle it, then the BLL could still throw another exception because of an improperly handled error in the DAL.

The general rule goes like this:

Handle Specific errors and dont use a generic catch-all. Allow any unanticipated exceptions to bubble further up the stack.

Try running FxCop on your project to see where you are violating best practices. http://www.gotdotnet.com/team/fxcop

A: 

Your library code or the code that is used by higher-layers in your application must always only throw exceptions and never worry about how to deal with them.

This is important because you may use this library at many places for different purposes.

In your application presentation layer, if you're consuming a library code and you're aware about the possible exceptions then do catch them with try/catch.

this. __curious_geek