ASP.Net/Page/Page Error — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 11:53, 26 мая 2010
Page_Error() method (VB.net)
<%@ Page Language="vb" %>
<html>
<head>
<title>Error event example</title>
<script runat="server">
Sub Page_Load()
Dim x, y, overflow As Integer
x = 1
y = 0
overflow = x / y
End Sub
Sub Page_Error()
Response.Write(Server.GetLastError.ToString())
Server.ClearError
End Sub
</script>
</head>
<body>
<asp:label id="Message" runat="server"/>
</body>
</html>
Page.ErrorPage property (VB.net)
<%@ Page Language="vb" %>
<html>
<head>
<title>ErrorPage property example</title>
<script runat="server">
Sub Page_Load()
Page.ErrorPage = Server.MapPath("ErrorPage_Handler.aspx")
Dim x, y, overflow As Integer
x = 1
y = 0
overflow = x/y
"This code will not be executed
Message.Text = "Error Page is " & Page.ErrorPage & "."
End Sub
</script>
</head>
<body>
<asp:label id="Message" runat="server"/>
</body>
</html>
<%--ErrorPage_Handler.aspx
<%@ Page Language="vb" %>
<html>
<head>
<title>ErrorPage property example</title>
<script runat="server">
Sub Page_Load()
Message.Text = "We"re sorry. An error occurred during the processing of your request. Please try again later."
End Sub
</script>
</head>
<body>
<asp:label id="Message" runat="server"/>
</body>
</html>
--%>
Page level error (C#)
<script Language="c#" runat="server">
void PageLevelErrorTest()
{
// Remove opening try
int[] array = new int[9];
for(int intCounter=0; intCounter <= 9;intCounter++)
{
array[intCounter] = intCounter;
Response.Write("The value of the counter is:" + intCounter + "<br>");
}
// Remove catch and finally blocks
}
void Page_Error(object sender, EventArgs e)
{
Response.Write("Error occurred: " + Server.GetLastError().ToString());
Server.ClearError();
}
void Page_Load()
{
PageLevelErrorTest();
}
</script>
<%
Response.Write("Function call completed" + "<br>");
%>