ASP
  Home arrow ASP arrow Page 4 - 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 - Third Trick: The Quick Debugger


    (Page 4 of 4 )

    If you’re at all like me, you will quickly be annoyed by typing and re-typing the same lines of code to read your offending variables, their type, size, and so forth. So, it’s always handy to have a subprocedure do all the work for you. Here’s a simple one:


    '=========================================================
    Sub debug( var )
    '
    =========================================================
        
    Response.Write("<span style=""font-size: 9pt;font-family: arial; font-weight: normal"">")
        
    Response.Write("<strong>Type = " typeName( var ) & "
    "
    )
        If 
    Not typeName( var ) = "Variant()" Then 
            Response
    .Write"Size = " len(var) & "
    )
            
    Response.Write"<u>Value</u></strong>
    )
    Response.WriteReplace( var, vbCrLf"
    "
    ) )
         Else
             
    Dim intDimsij
            intDims 
    CountDims( var )
            if 
    intDims 3 then
                
    For 0 to UBound( var, )
                    If 
    intDims 1 then
                         Response
    .Write("var( " " ): " )
    Response.Writetypename( var( ) ) & " = " )
    Response.Write( var( ) & "
    vbCrLf )
     Else
                        For 
    0 to UBound( var, )    
                            
    Response.Write("var( " ", " " ): " )
    Response.Writetypename( var( i) ) & " = " )
    Response.Write( var( i) & "
    vbCrLf )
                        
    Next
        
                    End 
    If
                
    Next
              
    Else
                
    Response.Write“array has “ intDims “ dimensions.” )    
            
    End If
        
    End If
        
    Response.Write("</span>")
        
    Response.End()
    End Sub


    For this to work on arrays, you’ll need the function below. Currently the debugger works with up to two dimensions, but could be modified to do more if that’s necessary within your application.


    <script language="JScript" runat="server">
        function 
    CountDimsarrVBArray ) {
            return 
    arrVBArray.dimensions();
        }
    </script>


    Basically, you could use the subprocedure debug() anywhere you want to see what a variable is in gory detail. What I have started doing is inserting it - commented out - in places where I could foresee errors occurring, such as when picking up Query String elements, or with SQL SELECT statements. Example:


    Dim intUserIDstrSQL
    intUserID 
    TrimRequest.QueryString(“intUserID”) )
    ‘debugintUserID )

    strSQL “SELECT FROM users WHERE id “ intUserID
    ‘debug
    strSQL )


    This way, when I need to do some quick debugging, I simply un-comment the desired line, and I’m well on my way to finding the cause of the error.

    Conclusion

    I hope you find these techniques as useful as I have. I can honestly say that using this method of error reporting has saved me hours of frustrated searching. I also believe that using the debugger has prevented carpal tunnel syndrome brought on by typing millions of Response.Write()- Response.End()’s.
    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

     

    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 5 Hosted by Hostway
    Stay green...Green IT