What are the exception-handling ways in ASP.NET?

What are the exception-handling ways in ASP.NET? Explain each way.

The ways by which the exceptions can be handled in ASP.NET are:

try-catch block:
- A code should be enclosed in this block to access the files,databases.
- There is a third part to this block called as finally.
- Use the Debug menu and the select Exception to view the exceptions that are supported by the .NET Framework.

Using Error Events:
- There are three errors used in conjunction with SEH so that all the exceptions are handled and used with messages:
1. Page_Error – It is a web form event which occurs within the web page.
2. Global_Error – It is in Global.asax file and occurs within the application.
3. Application_Error - It is in Global.asax file and occurs within the application.

Methods used in the Server object used to handle exceptions are:
1. GetLastError – It gets the last exception that had occurred on the server.
2. ClearError – This method is used to handle the exception and stop the error to trigger and subsequent event or display the error to the user.

Using the Custom Error Pages:
- They handle the HTTP exceptions such as the page not found,unauthorized access etc.
- They can be specified in two places:
1. customError section of the web.config file.
2. errorPage attribute of the directive @Page to display the error page for the generation of the error on a particular page.
Use of error pages in ASP.NET
ASP.NET - Use of error pages in ASP.NET - Error pages are used when exceptions are outside the scope of the application and the application can’t respond directly to these exceptions. ..
What is tracing in ASP.NET?
ASP.NET - What is tracing in ASP.NET? - Tracing records unusual events while an application is running...
Use of ComVisible attribute in ASP.NET
ASP.NET - Use of ComVisible attribute in ASP.NET - ComVisible attribute is used to select which public .NET classes and members are visible to COM.....
Post your comment