| << 9.4.0- Debugging ASP Script | Chapter9 | 9.4.2- Conditional Tracing >> |
Use Response.Write
This is one of the oldest methods of debugging, and involves putting in lots of trace statements that indicate where you are in aparticular script. If you remember, Response.Writewrites a line of text into the output stream, so this will be seen as text whenthe page is viewed. For example, consider the following ASP script that expectssome details from a Form on the previous ASP page.
<%
Dim strName
Dim strEmail
strName = Request.Form("Name")
strEmail = Request.Form("Email")
' do some complex processing with the form details
' do more processing
%>
Let's suppose an error occurs in the 'complex processing',and you have little idea what it is doing. Changing the script can help trackdown the problem:
<%
Dim strName
Dim strEmail
strName = Request.Form("Name")
strEmail = Request.Form("Email")
Response.Write "Debug: Name=" & strName& "<BR>"
Response.Write "Debug: Email=" &strEmail & "<BR>"
Response.Write "Debug: Now entering complexprocessing<BR>"
' do some complex processing with the form details
Response.Write "Debug: Complex processingfinished<BR>"
' do more processing
Response.Write "<HR>More processingfinished<BR>"
%>
Now when you run this script you'll see the name and emailaddress displayed before the processing starts, and this can tell you whetheror not they are correct. If the last message does not appear, then you knowthat the error occurred before it got to this line.
Although a very simple idea it's extremely valuable, and isa technique I still use to debug complex ASP pages.
You can useanother method of the Response object, namely End to stop execution before hitting a trouble spot.You can then walk that Response.End down throughthe code.
| << 9.4.0- Debugging ASP Script | Chapter9 | 9.4.2- Conditional Tracing >> |

RSS
