What is three-tier architecture?


Business objects
Business objects will be maintained in a different project where all object required for database layer, business layer and presentation layer will be created and maintained. But according to me, we need to go for this layer only in case of following two scenario, other wise it better to omit this layer for the sake of not killing the application
1. A set of common object is used across in many classes.
2. When we got to implement logic in the get, set property of objects declared.

Database Layer
Database layer also becomes a different project. Database layer will contain all the methods required to connect to the database using connection string and execute the stored procedure.

Business Layer
Business layer will be a project that acts an intermediate layer between presentation layer and database layer. Like database layer, business layer also should be as generic as possible. All the (possible) logic that we need to do with data before appending it with controls in presentation layer can be implementing in business layer.

Presentation Layer
Final project created will be presentation layer. As we know the UI controls will be placed in this layer. On control related events the methods from business layer can be invoked and operation could be executed.

Utility Layer
Utility layer does not actually belong to 3 tier layer. But we can create a custom exception class inside this utility layer and be used in all the 3 layers to handle the errors that occurring with in the application.

Handling errors in Asp.net application

Until yesterday what I thought about handling exception was just using try catch (that too a general catch) wherever possible and that’s it. Done! When my lead asked me if some one tries to transfer fund from his account to his clients and mean while system threw some exception. But since you have used general exception and did not handle it. How would it look like? The user will assume that money has got transferred, the client will keep waiting for the money to get deposited, and you the developer never knew that an error has happened inside nor you can trace it! Surely it will be disastrous! Now how to go about solving this problem?

  1. We should never a general exception handling any where. If some error happens, let it happen. So that you know that something has gone wrong. Hiding such bug is not going to help any one.
  2. Catch only expected bugs. Use the exact exception class to handle the error you expect. 

Earlier some one has misguided me that try catch is used to hide occurring bugs from the user. But today I realize that try catch is actually implemented to let the responsible person know that some thing wrong has happened. But yes off course using try catch we should be able to prevent the application from getting crashed. How do we let the responsible people know about this issue, specifically if the error happened to occur in database layer or business layer?

The methods written inside the database layer and business layer will be used as sub methods to events and methods written in UI layer. So the error occurred in DB layer and BL layer need to be communicated to UI layer using ‘throw exception’ command unless the responsible guys are never going to know about this. We can have a Custom exception class for implementing this. The custom exception can be created by merely overriding all the methods of System Exception class. Now using the overridden methods we can throw the exceptions from DB layer and BL layer, after that we can catch the exception using custom exception class itself from UI layer. Now we can let the responsible know about the issue by redirecting the application to an error page and display the message there or using a message box.