ASP
  Home arrow ASP arrow Page 3 - Easy Error Management
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP

Easy Error Management
By: Justin Cook
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 29
    2003-12-08

    Table of Contents:
  • Easy Error Management
  • First Trick: Checking for Truly Numeric Values
  • Second Trick: User-Friendly Error Reporting
  • Third Trick: The Quick Debugger

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Easy Error Management - Second Trick: User-Friendly Error Reporting


    (Page 3 of 4 )

    The second trick involves two steps. The first step is the oh-so-vital “friendly” error message. This is a necessity because, generally speaking, when one sees “Microsoft VBScript runtime error,” there is no obvious plan of action associated with it, leaving both the user and programmer stranded. The second step, admittedly an optional one, is to take the responsibility of reporting the error off of the user, by having the error emailed to you, tracked in a database, or both.

    Step 1 - Placate the User

    So, we have to stop users from being scared off by ASP’s inherent, and somewhat cryptic, error messages. This can be accomplished with some soothing color, and a calming explanation of what on earth is wrong. Take a look at the following:


    '=========================================================
    Sub errorMessage( strMSG ) 
    '
    =========================================================
        
    dim blOptionalInfo    
        
        blOptionalInfo 
    false 
    === you can hard-code to true/false, or have it depending on permissions
        
        
    Response
    .Write"<div align=""left"" style=""font: 10pt verdana, arial;margin: 25px;")
        
    Response.Write"padding:1em;background-color:#E6EAF7; border: 1px solid #BDCFDE"">")
        
    Response.Write"<h3>You have encountered an error!</h3>" )
        
    Response.WritestrMSG )
        
    If 
    blOptionalInfo Then
     Response
    .Write"<p><b>Debug Info:</b>
    )
         
    Response.Write"URL: " Request.ServerVariables("URL") & "
    )
         
    Response.Write"QUERY_STRING: " Request.ServerVariables("QUERY_STRING") & "
    )
         
    Response.Write"RU: " Request.ServerVariables("REMOTE_USER") & "
    )
         
    Response.Write"RA: " Request.ServerVariables("REMOTE_ADDR") & "
    )
    End if

        
    Response.WriteNow() )
        
    Response.Write"<p><a href=""javascript:history.back()"">Go back</a>
    "
    )
        
    Response.Write"<a href=""/"">Home</a>" )
        
    Response.Write"</div>" )
        
    Response.End()
    End Sub


    Explanation: Here we are telling the user in plain English what has just happened, where they are, how they got there, and where to go from here. Here’s an example:


    If Not isTrulyNumericintUserID Then
        Call errorMessage
    ("The user id you have supplied is invalid! (“ & intUserID & “)” )
     Else
        ‘proceed
    End If


    This method of reporting will make your programming life much easier and your users happier, guaranteed or your money back!

    Step 2 - Obtaining Omniscience

    Imagine you were the one contacting a user about an error they encountered, not vice versa. Imagine that not only were you able to explain the error quickly, but also explain that you’ve already fixed it! Imagine the enormous amounts of trust and respect (not to mention $$) that would be heaped upon you!

    This is fairly easy to accomplish. All you need to do, is create another subprocedure for emailing/logging the error, and call it from the errorMessage() subprocedure. You’ll want to modify the code below with the all variants you wish to be tracked.


    '=========================================================
    Sub reportError( strMSG ) 
    '
    =========================================================
        
    dim arVarsobjMailstrBodyi
        
        redim arVars
    # of items to track )
    arVars) = “error:” strMSG
    arVars
    ) = “time:” now()
    arVars) = “user id:” intUserID
    arVars
    ) = “page:” Request.ServerVariables("URL")
    arVars) = “querystring:” Request.QueryString()
    arVars) = “form data:” Request.Form()
    arVars# ) = etc…

    set objMail     Server.CreateObject(“CDONTS.NewMail”)
    objMail.To      “youremail@domain.com”
    objMail
    .Subject “error report”

    strBody 
    “the following error was encountered” vbCrLf vbCrLf

    For 0 To UBoundarVars )
        
    strBody strBody arVars) & vbCrLf
    Next

    objMail
    .Body strBody
    objMail
    .Send()

    Set objMail Nothing
    arVars 
    Null

    ‘followed by optional tracking in a database
     
    End Sub


    So there you have it! With good planning, you can be made aware of 99% of all the errors that occur within your application, without depending on the user to notify you. Lastly, let’s just look at one handy trick to save time with our debugging.

    More ASP Articles
    More By Justin Cook


     

    ASP ARTICLES

    - Using MySQL with ASP
    - ADO for the Beginner
    - ADO.NET 101: Data Rendering with a DataGrid ...
    - Introducing SoftArtisans OfficeWriter 3.0 En...
    - Getting Remote Files With ASP
    - The Real Basics of Functions in ASP
    - Enhancing Readability with ASP
    - Mimicking PHP's String Formatting Functions
    - Windows Server Hacks 12, 77, and 98
    - How to Sort a Multi-Dimensional Array
    - Developing an Information Management Tool wi...
    - What are Active Server Pages?
    - Getting Remote Pages with ASP
    - FTP’ing Files with ASP
    - Apply Single-Sign-On to Your Application





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    Stay green...Green IT