|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread |
Rating:
|
Display Modes |
|
|
|
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today! |
|
#1
|
||||
|
||||
|
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
__________________
selwonk If I've posted some code above, you might think it looks a bit simplistic. It might be. I'd rather people tried the next step themselves rather than getting a full solution on a plate. That way they learn more! |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
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.
|
|
#4
|
||||
|
||||
|
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 |
|
#5
|
||||
|
||||
|
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 |
|
#6
|
||||
|
||||
|
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..." |
|
#7
|
||||
|
||||
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. |
|
#8
|
|||
|
|||
|
Quote:
Hey thanks a lot for that little hint of your's using the "Response.End" technique. I certainly will use that code. Thanks again. |
|
#9
|
|||
|
|||
|
Hi all,
Script Debugger IDE can be found at http://www.script-debugger.com/ which enables Client and Server side debugging features. A free script Client and Server sides script debugger can be found at http://www.microsoft.com/downloads/...&displaylang=en Regards, Orlando Otero |
|
#10
|
|||
|
|||
|
The simplest way to debug ASP code is to use Response.Write statements along with Response.End.
__________________
ASP ASP hosting SQL Tutorial SQL Strings Loans Canada C D SQL Dictionary Hosting Dictionary Tech Dictionary Job Bank Canada |
|
#11
|
||||
|
||||
|
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. |
|
#12
|
|||
|
|||
|
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>
|
|
#13
|
||||
|
||||
|
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. |
|
#14
|
||||
|