Click here to Skip to main content
13,054,779 members (73,997 online)
Click here to Skip to main content


22 bookmarked
Posted 20 May 2008

Handling Error Centrally in a SharePoint Application

, 20 May 2008
An article on handling errors centrally in a SharePoint application, using IHttpModule.
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 MyErrorHandler : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
        if (!Page.IsPostBack)

            if (HttpContext.Current.Application.Get("LastException") != null)

                    Exception ex = (Exception)HttpContext.Current.Application.Get("LastException");
                    string Code = (string)HttpContext.Current.Application.Get("ErrorCode");
                    uxErrorMessage.Text = ex.Message;
                    uxStackTrace.Text = ex.StackTrace;
                    uxErrorCode.Text = Code;
                catch (Exception exc)
                    uxErrorMessage.Text = exc.Message;
                    uxStackTrace.Text = exc.StackTrace;
                    uxErrorCode.Text = "Unexpected Error";

                uxErrorMessage.Text = "Does not contain any information about error!!!";
                uxStackTrace.Text = "Not available!";
                uxErrorCode.Text = "Not available!";


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Anupam Ranku
Software Developer (Senior) Gen-i, Australia
Australia Australia
Expertise area: ASP.NET, C#, Microsoft Office SharePoint 2010 & 2007, Web Service, Windows-based Applications etc.


You may also be interested in...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170713.1 | Last Updated 20 May 2008
Article Copyright 2008 by Anupam Ranku
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid