Page 121 - DCAP312_WEB_TECHNOLOGIES_II
P. 121
Unit 6: Error Handling
</customErrors> Notes
</system.web>
<configuration>
The <customErrors> section has the possible attributes:
Mode:
It enables or disables custom error pages. It has the three possible values:
On: displays the custom pages.
Off: displays ASP.NET error pages (yellow pages).
Remote Only: displays custom errors to client, display ASP.NET errors locally.
DefaultRedirect:
It contains the URL of the page to be displayed in case of unhandled errors.
To put different custom error pages for different type of errors, the <error> sub tags are used,
where different error pages are specified, based of the status code of the errors.
To implement page level error handling, the Page directive could be modified:
<%@ Page Language= “C#” AutoEventWireup= “true”
CodeBehind= “Default.aspx.cs”
Inherits= “errorhandling._Default”
Trace = “true”
ErrorPage= “PageError.htm” %>
6.3 Levels of Error Handling
There are different levels where you could handle exceptions.
• Locally (method level), where exceptions could be thrown.
• Page level by handling thePage.Error event.
• Application level by handling the HttpApplication.Error event.
• HTTP Module level by handling the HttpApplication.Error event.
6.3.1 Local Error Handling
Drape code that might fling exceptions in a try-catch-finally block. If you can get better from the
exemption, then handle it in the catch block. If the exception cannot be improved from locally,
let the exception propagate to higher levels by throwing it. If the exception cannot be recovered
from locally, but additional information can be provided, then wrap the exception with the new
information and throw the new exception. This method is used when you use custom exceptions.
Place the clean up code in the finally block.
6.3.2 Page Level
Attach a handler to the Page.Error event. In C#, you will have to write the event wire up code
yourself in the Page Load method.
When an exception goes unhandled in a page, the Error event of the Page group of pupils gets
triggered.
LOVELY PROFESSIONAL UNIVERSITY 115