www.evidhyashala.com provides free free mock test , free online exam , online exam free test series , online exam free , Online Test Exam Series , free exam papers past papers , online exam form ,Online Test Series for Exam Prep. Free Mock Tests - for All govt jobs. Bank PO, Clerk, SSC CGL, CHSL, JE, GATE, Insurance, Railways, IBPS RRB, SBI, RBI, IPPB, BSNL TTA

Sponser Link

know more info pls click here

What are Error Events?-interview04032012

Another way to handle exceptions is through the Web objects’ built-in error events. When an unhandled exception occurs in a Web application, ASP.NET fires the error events shown below. Page_Error : Occurs when an unhandled exception occurs on the page. This event procedure resides in the Web form. Global_Error : Occurs when an unhandled exception occurs in the application. This event procedure resides in the Global.asax file. Application_Error : Occurs when an unhandled exception occurs in the application. This event procedure resides in the Global.asax file. Error events let you handle exceptions for an entire object in a single, centralized location—the error event procedure. This is different from using exception-handling structures, in which exceptions are handled within the procedure where they occurred. You can use error events in the following ways: As a substitute for exception-handling structures : Because error events occur outside the scope of the procedure in which the error occurred, you have less information about the steps leading up to the exception and therefore less ability to correct the exception condition for the user. However, using exception-handling events is fine for tasks where you might not be able to correct the exception in code. As an adjunct to exception-handling structures : Error events can provide a centralized “backstop” against exceptions that were not foreseen or handled elsewhere. Using the two exception-handling techniques together lets you catch all exceptions before the user sees them, display a reasonable message, and even record the exception in a log as part of an ongoing effort to improve your application. Give an example to show how error events can be used to handle exceptions? To handle an exception using error events, follow these steps: 1. In the Page_Error event procedure, get the exception that occurred using the GetLastError method. 2. Do something with the exception, such as display a message to the user, take steps to correct the problem, or write to an error log. 3. Clear the exception using the ClearError method. 4. Redisplay the page. Web form processing stops immediately when an exception occurs, so server controls and other items on the page might not be displayed after the exception is cleared. 5. Add the following code to Page_Error event procedure on the web page. private void Page_Error(object sender, System.EventArgs e) { // Get the error. Exception ex = Server.GetLastError(); // Store the message in a session object. Session["Error"] = ex.Message; // Clear the error message. Server.ClearError(); // Redisplay this page. Server.Transfer("ErrorEvents.aspx"); } The preceding code stores the exception message as a Session state variable before clearing the exception so that the message can be displayed when the page is reloaded by the Transfer method. The following code displays the saved exception message when the page is redisplayed: Add the following code to Page_Load event procedure on the web page. private void Page_Load(object sender, System.EventArgs e) { // Display error. if any. if (Session["Error"] != null) { litError.Text = "The following error occurred: " + Session["Error"].ToString(); // Clear the Session state variable. Session["Error"] = null; } }

0 comments:

Popular Posts