ASP.Net/Page/Page Error

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

Page_Error() method (VB.net)

   <source lang="csharp">

<%@ 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>

      </source>
   
  


Page.ErrorPage property (VB.net)

   <source lang="csharp">

<%@ 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> --%>

      </source>
   
  


Page level error (C#)

   <source lang="csharp">

<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 + "
"); } // 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" + "
");

%>

      </source>