Page 1 of 3 123 Last
  • Jump to page:
    #1
  1. Contributing User
    ASP Scholar (3000 - 3499 posts)

    Join Date
    Jun 2004
    Posts
    3,072
    Rep Power
    194

    Debugging techniques


    Various debugging techniques can be useful in helping you to diagnose faults with your ASP scripts. I'd like to open the floor to our resident gurus and ask for suggestions and top tips to help our forum users debug their ASP scripts more effectively

    I would like to start with ASP error handling. To initiate error handling you should add the following line to your script:

    On Error Resume Next

    The line tells the ASP interpreter to continue with the script even if there is an error. You can find out more about error handling here:

    http://www.aspdev.org/articles/asp-error-handling/

    There are various reasons why you should want to implement error handling. However, if you are new to ASP, this line should be avoided until you find the need to use it to trap and handle errors properly

    More importantly, if you are experiencing problems with your ASP script, including "On Error Resume Next" in your script can stop the browser from displaying the error message and might stop you from tracking down the problem

    I would strongly recommend against using ASP error handling if you are new to ASP or if your application is in development

    Comments on this post

    • KuraofTyren agrees : :D
    http://www.MapDays.com | Find events wherever, whenever you want them

  2. #2
  3. No Profile Picture
    Contributing User
    ASP Explorer (0 - 99 posts)

    Join Date
    Jan 2005
    Location
    Mumbai
    Posts
    40
    Rep Power
    0

    Cool


    Hi MK,
    U have started a nice discussion.. When we used to develop somehuge application we used to
    have On error Resume Next commented in the first place . so u can identify the error,line of error & what
    type of error.. but when everything completed we remove the comment on the On error Resum next so
    the ourside world never knows the error.. that's a pretty good trick for error free code..
    Let me tell u me way of debugging..when there is an error occurs & u don't know the reason just
    put thread in forums.aspfree.com ..that's it ur error will be solved overnight..
    I'm using Microsoft Interdev to create my ASP application..there is a tab to choose Quick View..
    I frequently go to this and it throws me all javascript & html errors.
    That's it..

    anandham
  4. #3
  5. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Dec 2004
    Posts
    9
    Rep Power
    0
    I work on a large asp/database program. We have a debug session variable. When the session variable turns debugging on On Error Resume Next is not part of the code. This also protects the programmers from left over response.write statements that were put in for debugging. If debug isn't on they don't print. We use this because there are so many asp programs and stored procedures working in this program that errors crop up from usage we don't expect. This allows us to quickly check out problems.
  6. #4
  7. Contributing User
    ASP Scholar (3000 - 3499 posts)

    Join Date
    Jun 2004
    Posts
    3,072
    Rep Power
    194
    Sounds similar to one of my projects...
    Code:
    SHOWDEBUG = 0 ' 0-Off, 1-In source, 2-On page
    ...
    Sub Debug(str_Message)
    Select Case SHOWDEBUG
    Case 1
    	Response.Write(vbcrlf & "<!-- " & str_Message & " -->" & vbcrlf)
    Case 2
    	Response.Write(vbcrlf & "<font size=""2"" face=""Courier new"" color=""red"">" & str_Message & "</font><br>")
    End Select
    End Sub
  8. #5
  9. Web-Standards Evangelist
    ASP Skiller (1500 - 1999 posts)

    Join Date
    Nov 2003
    Posts
    1,522
    Rep Power
    19
    On the subject of ASP debugging.... didn't the now-discontinued Microsoft VisualInterDev support server-side VBS debugging in a very similar fashion to the way VS2003 does.

    Just wondering really... if it does, I'd certanly look into finding InterDev in the bargain bins
  10. #6
  11. Contributing User
    ASP Scholar (3000 - 3499 posts)

    Join Date
    Jun 2004
    Posts
    3,072
    Rep Power
    194
    I think you're right. If anybody is interested, I also wrote a client-side Windows application that collects debug information from a SQL Server table and displays it on the desktop. Useful for debugging remote or local applications. You add a single #include to your ASP script and then add debug statements like this:
    Code:
    TL_AppendTraceLog 0, "YourScript.asp", "Starting script..."
    It generates a visual debug report coloured depending on the debug level (in this case 0 - information)

    Comments on this post

    • thaminda agrees : Useful information
  12. #7
  13. The Constant Student
    ASP Adventurer (500 - 999 posts)

    Join Date
    Aug 2004
    Location
    England
    Posts
    914
    Rep Power
    38

    Wink Debugging For Me


    Bearing in mind I only work with pages of ASP with Javascript and HTML at the moment, I tend to simplify things as much as possible. As I think most people that use this site are in a similar position, I will explain a little further.

    ASP page
    If I know an ASP page is causing me difficulties I put a Response.End in the page and move it down a line until I find the offending line. Once I find the offending line I then copy out the code, if possible, and I produce a more simple page which allows me to identify exactly what is going on. I use response.write to output variables or just messages to the actual page, which usually gives me enough information to tell me why I'm being such as silly little girl!!! This approach is not always possible but it certainly helps get things off the ground.

    Javascript
    Similar to the above but I use alert() statements and response.end to output what is going on and this is usually enough to give me a clue. Again, I try to move the JavaScript to a new page and get it working in a simpler fashion.

    I always try to separate as much of the code as possible. If I know a function or sub routine is the offending item then again, I try and call this from a simple page and output the results step by step.

    I know this is very basic, but I hope this is helpful to others.

    Comments on this post

    • selwonk agrees : Nice...
    • EasyMeat agrees
  14. #8
  15. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Mar 2005
    Posts
    7
    Rep Power
    0

    Smile Hey thanks a lot for that little hint of your's using the "Response.End" technique.


    Originally Posted by PhilCollins99
    Bearing in mind I only work with pages of ASP with Javascript and HTML at the moment, I tend to simplify things as much as possible. As I think most people that use this site are in a similar position, I will explain a little further.

    ASP page
    If I know an ASP page is causing me difficulties I put a Response.End in the page and move it down a line until I find the offending line. Once I find the offending line I then copy out the code, if possible, and I produce a more simple page which allows me to identify exactly what is going on. I use response.write to output variables or just messages to the actual page, which usually gives me enough information to tell me why I'm being such as silly little girl!!! This approach is not always possible but it certainly helps get things off the ground.

    Javascript
    Similar to the above but I use alert() statements and response.end to output what is going on and this is usually enough to give me a clue. Again, I try to move the JavaScript to a new page and get it working in a simpler fashion.

    I always try to separate as much of the code as possible. If I know a function or sub routine is the offending item then again, I try and call this from a simple page and output the results step by step.

    I know this is very basic, but I hope this is helpful to others.

    Hey thanks a lot for that little hint of your's using the "Response.End" technique. I certainly will use that code. Thanks again.
  16. #9
  17. No Profile Picture
    Need hosting? I can help.
    ASP Adventurer (500 - 999 posts)

    Join Date
    Sep 2003
    Posts
    826
    Rep Power
    16
    The simplest way to debug ASP code is to use Response.Write statements along with Response.End.

    Comments on this post

    • rhyno agrees : I agree
    • kanenas.net agrees
  18. #10
  19. Frustrated Wizard
    ASP Hero (2000 - 2499 posts)

    Join Date
    Apr 2005
    Posts
    2,419
    Rep Power
    24
    What i do is going step by step through the code by commenting out code lines.
    Just starting with everything commented out and then going through it, uncommenting parts / lines of code. Then the place of the error will come up.

    Very easy to use.

    Comments on this post

    • PhilCollins99 agrees : I also do this. It works well for me most of the time.
  20. #11
  21. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Sep 2004
    Location
    istanbul
    Posts
    15
    Rep Power
    0

    this function can be useful.


    (for "logical" errors.)
    Code:
        <script language="jscript" runat="server">
        /*********************************
        anov (aka. "catdogfight")
        15:39 27.05.2005 : posted to aspfree forum
        **********************************/
        function log_(p){
        
        	/**************************
     		  Options
        	***************************/
        	var logging = true ; //Logging is open?
        
        	var file = "" ;  //filter with file name
        
        	var filter = null ; //filter with regex
        
        	var file_name = String( Request.ServerVariables("SCRIPT_NAME") ) ;
        
        	var file_name_begin = file_name.lastIndexOf("/") + 1 ;
        
        	file_name = file_name.slice( file_name_begin ) ;
        
        	/******************************/
        
        	if(!logging) return true;
        
        
        
        	if(file!="")
        	{
        		//Response.Write( file.indexOf(file_name)==-1 )
        		if(file.indexOf(file_name)==-1) return false ;
        	}
        
        	//debugging(filter instanceof RegExp )
        
        	if(filter instanceof RegExp)
        	{
        		if( filter.test( String(p) ) == false )
        		{
        			return false ;
        		}
        	}
        
        
        	var path = Server.MapPath(".")+"\\"+"log.txt"
        
        	var fso = Server.CreateObject("Scripting.FileSystemObject");
        	var f ;
        
        	if(fso.FileExists(path))
        	{
        		f = fso.OpenTextFile(path,8);
        	}
        	else
        	{
        		f = fso.CreateTextFile(path,true) ;
        	}
        
        	try
        	{
        	f.Writeline(p) ;
        	}
        	catch(e)
        	{
        		Response.Write("<h1>" + p + "</h1>" );
        	}
        	f.Close() ;
        
        	delete f,fso;
        }//end function
        
        function alert_( p )
        {
        	var lt = String.fromCharCode(60); // <
        	var gt = String.fromCharCode(62); // >
        	var t  = String.fromCharCode(39); // '
        
        	Response.Write(lt+"script"+gt+"alert('" + p + "')"+lt+"/script"+gt);
        }
        </script>
  22. #12
  23. Senior Fire Wizard
    ASP Mastermind (5000+ posts)

    Join Date
    Feb 2005
    Location
    Ashford, Kent. England
    Posts
    5,651
    Rep Power
    318
    This seems to come up a lot, so is probably worth adding here.

    If you are writing an sql query in asp and you are having problems with it, write it to the browser using

    Code:
     response.write strQuery	'  or whatever your variable is called
     response.end
    You can instantly see the entire query and perhaps the error in it. If it looks ok, copy and paste it into the database front end and run it there, you may get a better error message.

    If it runs in the db, the quer is OK and the error lies elsewhere.

    Comments on this post

    • BlueSkyRanger agrees : I use this technique, too. Very helpful!
    And he picked it all up... in his pick-up.





    Friends of Shemzilla
  24. #13
  25. Web-Standards Evangelist
    ASP Skiller (1500 - 1999 posts)

    Join Date
    Nov 2003
    Posts
    1,522
    Rep Power
    19
    Of course, there is a MUCH easier way... provided that you have a good IDE.

    "Step-through debugging"... just launch your ASP/ASP.NET app in Debug mode, attach to the process, then trigger a breakpoint and you can follow through each line, watch variables and params, etc...
  26. #14
  27. Senior Fire Wizard
    ASP Mastermind (5000+ posts)

    Join Date
    Feb 2005
    Location
    Ashford, Kent. England
    Posts
    5,651
    Rep Power
    318
    This one works if you are prt of a team.

    Get someone else to look at the code with you. When you are explaining how
    the code works so they know what's going on, you will find the bug.

    This sounds like a joke, but works well and it works because of the detail you
    are having to explain the code in.
  28. #15
  29. No Profile Picture
    Registered User
    ASP Explorer (0 - 99 posts)

    Join Date
    Aug 2005
    Location
    wales
    Posts
    17
    Rep Power
    0

    response.write rocks


    I agree with all but using IDE debuggers is just faffy. Using is response.write with a .end as well rules.

    I guess though it does depend on the size of your app.

    good discussion. cheers dudes.
Page 1 of 3 123 Last
  • Jump to page:

Similar Threads

  1. Tip: Debugging a local web application using IIS
    By tonante in forum .NET Development
    Replies: 0
    Last Post: January 27th, 2005, 06:27 PM
  2. Improving Web application performance using caching techniques
    By sivakumar.k in forum Development Articles
    Replies: 0
    Last Post: August 27th, 2004, 09:15 AM
  3. Debugging problem in VS.NET
    By nickyowen99 in forum .NET Development
    Replies: 3
    Last Post: May 27th, 2004, 01:01 PM
  4. debugging asp in interdev 6.0
    By paurav in forum ASP Development
    Replies: 2
    Last Post: April 19th, 2004, 12:14 PM
  5. DEBUGGING problem with ASP.NET
    By User123 in forum .NET Development
    Replies: 5
    Last Post: September 25th, 2003, 04:17 AM

IMN logo majestic logo threadwatch logo seochat tools logo