Understanding Error Handling in ASP.NETWhen 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: 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, its 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.
|