Click here to Skip to main content
15,886,780 members
Articles / Web Development / IIS

User Friendly ASP.NET Exception Handling

Rate me:
Please Sign up or sign in to vote.
4.80/5 (70 votes)
20 Dec 20049 min read 667.5K   4.3K   344  
A flexible framework for user-friendly ASP.NET exception handling, and automatically notifying developers of problems before users do.
Imports System.Web

''' <summary>
''' Implements ASP unhandled exception manager as a HttpModule
''' </summary>
''' <remarks>
''' to use:
'''    1) place ASPUnhandledException.dll in the \bin folder
'''    2) add this section to your Web.config under the &lt;system.web&gt; element:
'''         &lt;httpModules&gt;
'''	 	        &lt;add name="ASPUnhandledException" 
'''                 type="ASPUnhandledException.UehHttpModule, ASPUnhandledException" /&gt;
'''		    &lt;/httpModules&gt;
'''
'''  Jeff Atwood
'''  http://www.codinghorror.com/
''' </remarks>
Public Class UehHttpModule
    Implements IHttpModule

    Public Sub Init(ByVal Application As System.Web.HttpApplication) Implements System.Web.IHttpModule.Init
        AddHandler Application.Error, AddressOf OnError
    End Sub

    Public Sub Dispose() Implements System.Web.IHttpModule.Dispose
    End Sub

    Protected Overridable Sub OnError(ByVal sender As Object, ByVal args As EventArgs)
        Dim app As HttpApplication = CType(sender, HttpApplication)
        Dim ueh As New Handler
        ueh.HandleException(app.Server.GetLastError)
    End Sub
End Class

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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
My name is Jeff Atwood. I live in Berkeley, CA with my wife, two cats, and far more computers than I care to mention. My first computer was the Texas Instruments TI-99/4a. I've been a Microsoft Windows developer since 1992; primarily in VB. I am particularly interested in best practices and human factors in software development, as represented in my recommended developer reading list. I also have a coding and human factors related blog at www.codinghorror.com.

Comments and Discussions