Click here to Skip to main content
15,889,873 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
This is more of a debate than a question .. Where should you put exception handling in N-tier ASP.NET application ?

1> Application_Error in Global.asax
2> Data Access Layer
3> Business Logic Layer
4> Code behind

I read some articles and they all have different view on it.
Posted

Found a thread with similar question(See the first answer).
Exception handling in n-tier applications?[^]
 
Share this answer
 
Well, it make sense to have a global handler that would display a generic page on error and possibly also catch unauthorized access so that an appropriate page would be displayed instead.

I think it is advisable to limit the number of error page to avoid giving too much information in case of an unexpected problem so that user won't gain too much knowledge about application weak points.

Other than that, in some case, it make sense to catch specific exceptions that might occurs when the database is updated and constraints are violated and it is related to user input. A typical case would be column that need to have unique values. If the insertion fails, appropriate error will be displayed on the page.

Sometime it might be impossible to validate before the actual change since multiple users might do changes almost simultaneously... Also, if the validation is quite complex, doing a validation before might double the response-time for no real benefit.

Having constraint at the database level help ensure that the constraints are always met even if multiple users are doing changes at the same time. But not all rules can be easily verified at that level.

In some case, a pre-validation will be done and we will "hope for the best". In many case, that approch would be acceptable if the chance of a conflict are very low and the consequences of a missed conflict are not too bad...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900