Understanding Error Handling in ASP.NET

When you write code to create a simple application, you will not be worried about errors and how to solve those errors. But while writing a complex web application, where the application relies on other programs, components, and objects, you have to assume that at some point of time errors will occur. This assumption will certainly help you to create a robust application. In normal ASP you would have tried On Error statement or try/catch statement to debug the errors. This was not a good solution because you have to build centralized error routines and provide a neat way to manage the errors.

Error handling in ASP.NET is quite simpler because of structured exception handling feature provided by Common Language Runtime (CLR). This feature is language independent and therefore if the exceptions are raised in one language, they can be fixed in another language. Moreover, you can fix exceptions that are raised on some remote .Net components. The exception handling system of .Net closely integrates with that of error handling in COM components. For example if you use .Net components from COM then the Windows HRESULT will be passed to the COM component when the exceptions are raised in .Net component. Similarly, if you use COM components from .Net and the COM component returns an HRESULT, this will be linked to a .Net exception. Apart from structured exception handling system, error handling in ASP.NET can be done in three ways:

• Page-level error

• Application-level error

• Declarative error handling in application configuration file

For page-level errors you can write the Page_Error event and for application-level error you can use Application_Error event. The declarative method can be used through web.config file and the pages can be configured with customErrors element. In enterprises, it’s not only users who need to know about errors, the administrators and the developers also need to be aware of the things that go wrong so that in future those errors do not recur. The user can either write an event in the Event Log or mail it to the administrator.


_______________________________________________________________________

_______________________________________________________________________

Add to My Yahoo!


FREE Subscription

Subscribe to our mailing list and receive new articles
through email. Keep yourself updated with latest
developments in the industry.

Name:
Email:

Note : We never rent, trade, or sell my email lists to
anyone. We assure that your privacy is respected
and protected.

Visit .NET Programming Tutorial Homepage

______________________________________________________

Recommended Resource


Privacy Policy for www.dotnet-guide.com