<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="PageExceptionTest" %>
Demonstration of Page_Error Handler
File: Default.aspx.cs
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class PageExceptionTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
BuggyMethod();
}
private void BuggyMethod()
{
throw new ApplicationException("Your buggy code caused an exception.");
}
private void Page_Error(object sender, EventArgs e)
{
Exception ex = Server.GetLastError();
Response.Write("An error has occurred
");
Response.Write("" + ex.Message + "
");
Response.Write("" + ex.StackTrace + "
");
Context.ClearError();
}
}