This is a discussion on Can u Explain Exception Handling Techniques in ASP.NET 2005 using error events? within the ASP and ASP.NET Programming forums, part of the Web Development category; Can u Explain Exception Handling Techniques in ASP.NET 2005 using error events?...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| There are three different error events in ASP.NET that can be used in conjunction with SEH so that all exceptions are handled and the user is presented with a user-friendly error message. 1. Page_Error: Occurs when an error occurs within the Web page. This event is in the Web form. 2. Global_Error: Occurs when an error occurs within the application. This event is in the Gloabl.asax file. 3. Application_Error: Occurs when an error occurs within the application. This event is in the Gloabl.asax file. Methods in the Server object are used to handle the exception in the error events. 1. GetLastError: Gets the last exception that occurred on the server. 2. ClearError: Use this method to handle the exception and stop the error to trigger the subsequent error event or display the error to the user. In the following code, you handle the exception in all the above three mentioned events but call the ClearError method only in the Application_Error event so that the error is propogated to the above level. private void Page_Error(object sender, System.EventArgs e) { Exception ex = Server.GetLastError(); Response.Write("Handled error from Page<br>"); //Server.ClearError(); } protected void Application_Error(Object sender, EventArgs e) { Exception ex = Server.GetLastError(); Response.Write("Handled error from Application <br>"); Server.ClearError(); } protected void Global_Error(Object sender, EventArgs e) { Exception ex = Server.GetLastError(); Response.Write("Handled error from Global <br>"); } |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Error Handling in PHP | sivaramakrishnan | PHP Programming | 13 | 09-21-2007 05:03 AM |
| How can I do error handling in php? | itbarota | PHP Programming | 1 | 09-12-2007 03:56 AM |
| How can I do error handling in php? | itbarota | PHP Programming | 0 | 09-12-2007 12:39 AM |
| Explain Exception Handling in SQL Server 2005. | Archer | Database Support | 2 | 08-30-2007 03:04 AM |
| What is Structured Exception Handling? | anbuchezhians | VB.NET Programming | 1 | 07-27-2007 08:46 AM |