ASP.Net/Server/Server Error — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 15:30, 26 мая 2010
Содержание
Examining the Last Error (VB.net)
<%@ Page Language="VB" %>
<html>
<head>
<title>Examining the Last Error</title>
<script runat="server">
Sub CauseError(sender As Object, e As EventArgs)
Dim x, y, z As Integer
y = 1
z = 0
x = y / z
End Sub
Sub Page_Error(Source As Object, E As EventArgs)
Dim LastError As Exception
Dim ErrMessage As String
LastError = Server.GetLastError()
If Not LastError Is Nothing Then
ErrMessage = LastError.Message
Else
ErrMessage = "No Errors"
End If
Response.Write("Last Error = " & ErrMessage & "<br/><br/>")
Server.ClearError()
End Sub
</script>
</head>
<body>
<form runat="server">
<h4><font face="verdana">Cause an Error to Occur...</font></h4>
<asp:button text="CauseError" OnClick="CauseError" runat="server"/>
</form>
</body>
</html>
Get last error and clear error stack trace (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>");
%>
Get string format server string (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>
Server.ClearError (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>