File: Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="ErrorHandlingTest" %>
Untitled Page
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;
using System.Drawing;
public partial class ErrorHandlingTest : System.Web.UI.Page
{
protected void cmdCompute_Click(object sender, EventArgs e)
{
try
{
decimal a, b, result;
a = Decimal.Parse(txtA.Text);
b = Decimal.Parse(txtB.Text);
result = a / b;
lblResult.Text = result.ToString();
lblResult.ForeColor = Color.Black;
}
catch (Exception err)
{
lblResult.Text = "Message: " + err.Message;
lblResult.Text += "
";
lblResult.Text += "Source: " + err.Source;
lblResult.Text += "
";
lblResult.Text += "Stack Trace: " + err.StackTrace;
lblResult.ForeColor = Color.Red;
}
}
}