Page 116 - DCAP312_WEB_TECHNOLOGIES_II
P. 116
Web Technologies-II
Notes The default Redirect attribute specifies the path to a generic error page.
Each error element defines a redirect specific to a particular HTTP status code. For example,
if the error is a 404 (File Not Found), then you could set the error page as FileNotFound.htm.
You could add as many error elements in the custom Errors section as required, each of which
specifies a status code and the corresponding error page path. If ASP.NET cannot find any
specific error element corresponding to a status code, it would use the value specified in the
default Redirect attribute.
Write a program to handle an exception using try-cache block.
6.2 Aspects of Error Handling
Following aspects are defined fir error handling:
Tracing: tracing the program execution at page level or application level.
Error handling: handling standard errors or custom errors at page level or application level.
Debugging: stepping through the program, setting break points to analyze the code.
To understand the concepts, create the following sample application. It has a label control,
a dropdown list and a link. The dropdown list loads an array list of famous quotes and the
selected quote is shown in the label below. It also has a hyperlink which has a nonexistent link.
<%@ Page Language= “C#”
AutoEventWireup= “true”
CodeBehind= “Default.aspx.cs”
Inherits= “errorhandling._Default” %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0
Transitional//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.
dtd”>
<html xmlns= “http://www.w3.org/1999/xhtml” >
<head runat= “server”>
<title>Tracing, debugging and error handling</title>
</head>
<body>
<form id= “form1” runat= “server”>
<div>
<asp:Label ID= “lblheading” runat= “server”
Text= “Tracing, Debugging and Error Handling”>
</asp:Label>
<br />
<br />
<asp:DropDownList ID= “ddlquotes”
runat= “server” AutoPostBack= “True”
o nse le ct ed ind ex ch ang ed = “ dd lq uot es_
SelectedIndexChanged”>
110 LOVELY PROFESSIONAL UNIVERSITY