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.

| What is the need for Bridge Pattern in C#? | What is the need for Builder Pattern in C#? | What is the need for Chain of Responsibility Pattern in C#? | What is the need for Command Pattern in C#? | What is the need for Composite Pattern in C#? | What is the need for Decorator Pattern in C#? | What is the need for Flyweight Pattern in C#? | What is the need for Interpreter Pattern in C#? | What is the need for Iterator Pattern in C#? | What is the need for Mediator Pattern in C#? | What is the need for Memento Pattern in C#? | What is the need for Prototype Pattern in C#? | What is the need for State Pattern in C#? | What is the need for Strategy Pattern in C#? | What is the need for Template Method Pattern in C#? | What is the need for unsafe code in C#? | What is the purpose of assert() in C#? | What is the purpose of AutoResetEvent in .NET? | What is the purpose of Console.ReadLine() in C#? | What is the purpose of machine.config file in .NET? |


“Amazon and the Amazon logo are trademarks of Amazon.com, Inc. or its affiliates.”

| Privacy Policy for www.dotnet-guide.com | Disclosure | Contact |

Copyright - © 2004 - 2024 - All Rights Reserved.