173 lines
11 KiB
HTML
173 lines
11 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
|
|
<html dir=ltr><head><title>Debugging ASP Scripts</title>
|
|
|
|
<SCRIPT LANGUAGE="JavaScript">
|
|
<!--
|
|
TempString = navigator.appVersion
|
|
if (navigator.appName == "Microsoft Internet Explorer"){
|
|
// Check to see if browser is Microsoft
|
|
if (TempString.indexOf ("4.") >= 0){
|
|
// Check to see if it is IE 4
|
|
document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/coua.css">');
|
|
}
|
|
else {
|
|
document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/cocss.css">');
|
|
}
|
|
}
|
|
else if (navigator.appName == "Netscape") {
|
|
// Check to see if browser is Netscape
|
|
document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/coua.css">');
|
|
}
|
|
else
|
|
document.writeln('<link rel="stylesheet" type="text/css" href="/iishelp/common/cocss.css">');
|
|
//-->
|
|
</script>
|
|
|
|
|
|
|
|
<META NAME="DESCRIPTION" CONTENT="This topic describes how to use the Microsoft Script Debugger to find and correct ASP scripting errors."><META HTTP-EQUIV="Content-Type" content="text/html; charset=Windows-1252">
|
|
<META HTTP-EQUIV="PICS-Label" CONTENT='(PICS-1.1 "<http://www.rsac.org/ratingsv01.html>" l comment "RSACi North America Server" by "inet@microsoft.com <mailto:inet@microsoft.com>" r (n 0 s 0 v 0 l 0))'>
|
|
<META NAME="MS.LOCALE" CONTENT="EN-US">
|
|
<META NAME="MS-IT-LOC" Content="Internet Information Services">
|
|
|
|
</head>
|
|
|
|
<body bgcolor="#FFFFFF" text="#000000">
|
|
|
|
<font face="Verdana,Arial,Helvetica">
|
|
|
|
|
|
<h1><a name="debuggingaspscripts">Debugging ASP Scripts</a></h1>
|
|
|
|
|
|
<p>Regardless of your level of experience, you will encounter programmatic errors, or <em>bugs</em>, that will prevent your server-side scripts from working correctly. For this reason, debugging, the process of finding and correcting scripting errors, is crucial for developing successful and robust ASP applications, especially as the complexity of your application grows.</p>
|
|
|
|
<h2><a name="themicrosoftscriptdebuggertool">The Microsoft Script Debugger Tool</a></h2>
|
|
|
|
<p>The Microsoft® Script Debugger is a powerful debugging tool that can help you quickly locate bugs and interactively test your server-side scripts. With Script Debugger, which also works with Windows Internet Explorer version 3.0 or later, you can:</p>
|
|
|
|
<ul>
|
|
<li>Run your server-side scripts one line at a time.</li>
|
|
<li>Open a command window to monitor the value of variables, properties, or array elements, during the execution of your server-side scripts.</li>
|
|
<li>Set pauses to suspend execution of your server-side scripts (using either the debugger or a script command) at a particular line of script.</li>
|
|
<li>Trace procedures while running your server-side script.</li>
|
|
</ul>
|
|
|
|
<p><strong>Note</strong> You can use the debugger to view scripts and locate bugs, but not to directly edit your scripts. To fix bugs, you must edit your script with an editing program, save your changes, and run the script again.</p>
|
|
|
|
<h2><a name="enablingdebugging">Enabling Debugging</a></h2>
|
|
|
|
<p>Before you can begin debugging your server-side scripts, you must first configure your Web server to support ASP debugging. For instructions and information, see <a href="../core/iiwarndd.htm">Enabling ASP Debugging</a>.</p>
|
|
|
|
<p>After enabling Web server debugging, you can use either of the following methods to debug your scripts:</p>
|
|
|
|
<ul>
|
|
<li>Manually open Script Debugger to debug your ASP server-side scripts.</li>
|
|
<li>Use Internet Explorer to request an .asp file. If the file contains a bug or an intentional statement to halt execution, Script Debugger will automatically start, display your script, and indicate the source of the error.</li>
|
|
</ul>
|
|
|
|
<h2><a name="scriptingerrors">Scripting Errors</a></h2>
|
|
|
|
<p>While debugging your server-side scripts you might encounter several types of errors. Some of these errors can cause your scripts to execute incorrectly, halt the execution of your program, or return incorrect results.</p>
|
|
|
|
<h3><a name="syntaxerrors">Syntax Errors</a></h3>
|
|
|
|
<p>A <em>syntax</em> error is a commonly encountered error that results from incorrect scripting syntax. For example, a misspelled command or an incorrect number of arguments passed to a function generates an error. Syntax errors can prevent your script from running.</p>
|
|
|
|
<h3><a name="runtimeerrors">Run-Time Errors</a></h3>
|
|
|
|
<p><em>Run-time</em> errors occur after your script commences execution and result from scripting instructions that attempt to perform impossible actions. For example, the following script contains a function that divides a variable by zero (an illegal mathematical operation) and generates a run-time error:</p>
|
|
|
|
<pre><SCRIPT LANGUAGE=VBScript RUNAT=SERVER>
|
|
Result = Findanswer(15)
|
|
Document.Write ("The answer is " &Result)
|
|
|
|
Function Findanswer(x)
|
|
'This statement generates a run-time error.
|
|
Findanswer = x/0
|
|
End Function
|
|
</SCRIPT></pre>
|
|
|
|
<p>Bugs that result in run-time errors must be corrected for your script to execute without interruption.</p>
|
|
|
|
<h3><a name="logicalerrors">Logical Errors</a></h3>
|
|
|
|
<p>A <em>logical</em> error can be the most difficult bug to detect. With logical errors, which are caused by typing mistakes or flaws in programmatic logic, your script runs successfully, but yields incorrect results. For example, a server-side script intended to sort a list of values may return an inaccurate ordering if the script contains a > (greater than) sign for comparing values, when it should have used a < (less than) sign.</p>
|
|
|
|
<h2><a name="errordebuggingtechniques">Error Debugging Techniques</a></h2>
|
|
|
|
<p>You can use several different debugging techniques to locate the source of bugs and to test your applications.</p>
|
|
|
|
<h3><a name="justintimedebugging">Just-In-Time (JIT) Debugging</a></h3>
|
|
|
|
<p>When a run-time error interrupts execution of your server-side script, the Microsoft Script Debugger automatically starts, displays the .asp file with a statement pointer pointing to the line that caused the error, and generates an error message. With this type of debugging, called <em>Just-In-Time</em> (JIT) debugging, your computer suspends further execution of the program. You must correct the errors with an editing program and save your changes before you can resume running the script.</p>
|
|
|
|
<h3><a name="breakpointdebugging">Breakpoint Debugging</a></h3>
|
|
|
|
<p>When an error occurs and you cannot easily locate the source of the error, it is sometimes useful to preset a <em>breakpoint</em>. A breakpoint suspends execution at a specific line in your script. You can set one or many different breakpoints before a suspect line of script and then use the debugger to inspect the values of variables or properties set in the script. After you correct the error, you can clear your breakpoints so that your script can run uninterrupted.</p>
|
|
|
|
<p>To set a breakpoint, open your script with Script Debugger, select a line of script where you want to interrupt execution, and from the <STRONG>Debug</STRONG> menu choose <STRONG>Toggle Breakpoint</STRONG>. Then use your Web browser to request the script again. After executing the lines of script up to the breakpoint, your computer starts the Script Debugger, which displays the script with a statement pointer pointing to the line where you set the breakpoint.</p>
|
|
|
|
<h4>The Break at Next Statement</h4>
|
|
|
|
<p>In certain cases, you may want to enable the Script Debugger <strong>Break at Next Statement</strong> if the next statement that runs is not in the .asp file that you are working with. For example, if you set <strong>Break at Next Statement</strong> in an .asp file residing in an application called Sales, the debugger will start when you run a script in any file in the Sales application, or in any application for which debugging has been enabled. For this reason, when you set <strong>Break at Next Statement</strong>, you need to be aware that whatever script statement runs next will start the debugger.</p>
|
|
|
|
|
|
<h3><a name="vbscriptstopstatementdebugging">VBScript Stop Statement Debugging</a></h3>
|
|
|
|
<p>You can also add breakpoints to your server-side scripts written in VBScript by inserting a <strong>Stop</strong> statement at a location before a questionable section of server-side script. For example, the following server-side script contains a <strong>Stop</strong> statement that suspends execution before the script calls a custom function:</p>
|
|
|
|
<pre><%
|
|
intDay = Day(Now())
|
|
lngAccount = Request.Form("AccountNumber")
|
|
dtmExpires = Request.Form("ExpirationDate")
|
|
|
|
strCustomerID = "RETAIL" & intDay & lngAccount & dtmExpires
|
|
|
|
'Set breakpoint here.
|
|
Stop
|
|
|
|
'Call registration component.
|
|
RegisterUser(strCustomerID)
|
|
%></pre>
|
|
|
|
<p>When you request this script, the debugger starts and automatically displays the .asp file with the statement pointer indicating the location of the <strong>Stop</strong> statement. At this point you could choose to inspect the values assigned to variables before passing those variables to the component.</p>
|
|
|
|
<p><strong><FONT COLOR="#0000FF">Important</FONT></strong> Remember to remove <strong>Stop</strong> statements from production .asp files.</p>
|
|
|
|
<h3><a name="jscriptdebuggerstatementdebugging">JScript Debugger Statement Debugging</a></h3>
|
|
|
|
<p>To add breakpoints to your server-side scripts written in JScript, insert a <strong>debugger</strong> statement before a suspect line of script. For example, the following script includes a <strong>debugger</strong> statement that interrupts execution and automatically starts Script Debugger each time the script loops through a new value.</p>
|
|
|
|
<pre><%@ LANGUAGE=JScript %>
|
|
<%
|
|
for (var count = 1; count <= 10; count++)
|
|
{
|
|
var eventest = count%2
|
|
//Set breakpoint so that user can step through execution of script.
|
|
debugger
|
|
if (eventest == 0)
|
|
Response.Write("Even value is " + count + "<br>")
|
|
}
|
|
%></pre>
|
|
|
|
<p>Remember to remove <strong>debugger</strong> statements from production .asp files.</p>
|
|
|
|
<p><strong>Note</strong> Do not confuse the <strong>debugger</strong> statement with the JScript <strong>break</strong> statement. The <strong>break</strong> statement exits a currently running loop during execution and does not activate the Microsoft Script Debugger, nor pause execution.</p>
|
|
|
|
<h2><a name="tipsfordebuggingscripts">Tips for Debugging Scripts</a></h2>
|
|
|
|
<p>Aside from Script Debugger, a good set of debugging tips can greatly reduce the amount of time you spend investigating the source of scripting errors. Although most bugs result from obvious sources, misspelled commands or missing variables, certain types of logical and execution errors can be hard to find.</p>
|
|
|
|
<p></P>For more information about Microsoft Script Debugger, see <a href="http://www.microsoft.com/isapi/redir.dll?prd=msdn&pver=6.0&ar=scripting" target=_blank><b>Windows Script Technologies</b></a>.
|
|
|
|
<hr class="iis" size="1">
|
|
<p align="center"><em><a href="/iishelp/common/colegal.htm">© 1997-2001 Microsoft Corporation. All rights reserved.</a></em></p>
|
|
|
|
</font>
|
|
|
|
</font>
|
|
</body>
|
|
|
|
</html>
|