Listing C
Sub Application_Error(ByVal sender As Object, _
 ByVal e As EventArgs)
    ' Get the actual error that brought us here
    Dim ex As Exception = _
     Server.GetLastError.InnerException
    ' Create a string with the error information
    Dim Message As StringBuilder = New StringBuilder( _
     "An error occurred in the application:" & vbCrLf)
    Message.Append(ex.Message & vbCrLf)
    Message.Append("Stack trace:" & vbCrLf)
    Dim s As StringBuilder = New StringBuilder(ex.StackTrace)
    Message.Append(s.Replace(" at ", " at " & vbCrLf))
    ' Mail the message to the developer
    SmtpMail.Send("App@sample.com", "Dev@sample.com", _
     "Application Error", Message.ToString())
    ' Clear the error
    Server.ClearError()
    ' Tell the user we're on top of it
    Response.Write("We're sorry, but an unexpected error has occurred")
    Response.End()
End Sub