IT Community - Software Programming, Web Development and Technical Support

Can u Explain Exception Handling Techniques in ASP.NET 2005 using error events?

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?...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > ASP and ASP.NET Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 07-25-2007, 03:09 AM
Archer Archer is offline
D-Web Programmer
 
Join Date: Jun 2007
Posts: 52
Archer is on a distinguished road
Question Can u Explain Exception Handling Techniques in ASP.NET 2005 using error events?

Can u Explain Exception Handling Techniques in ASP.NET 2005 using error events?
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-25-2007, 03:19 AM
kingmaker kingmaker is offline
D-Web Genius
 
Join Date: Jun 2007
Posts: 882
kingmaker is on a distinguished road
Send a message via Yahoo to kingmaker
Default Re: Can u Explain Exception Handling Techniques in ASP.NET 2005 using error events?

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>");
}
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT -7. The time now is 07:34 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0