Error messages are sent back as HTML with all or some the following information, depending upon the nature of the error:
Note Using a text editor that displays line numbers will help you locate a line with an error in your .asp file.
Use this information to modify the scripts so that the generated errors can be resolved. Errors of a severe nature will be sent to the Windows NT log and the Internet Information Server log, as well as to the Web browser. All other errors will be sent to the IIS log and Web browser.
If an error is encountered in your script, the processing of your page stops and an error message is returned to the browser. If you want to continue processing your page even if an error is encountered, include the following line at the beginning of your script:
<% On Error Resume Next %>
Note The On Error Resume Next statement is a VBScript statement; it affects only VBScript code. Using this statement within JScript code will have no effect on debugging because JScript has no functional equivalent of resuming after an error. If you call a JScript function from VBScript code and the JScript function causes an error, the error is returned to the browser and processing of the script stops at that point.
Using the On Error Resume Next statement does not actually clear an error; to manually clear the error, you can use the Err.Clear method:
<HTML> <TITLE>Error Handling with On Error Resume Next and Err.Clear</TITLE> <% Call DoSafeDivide(1, 3) %> <% Call DoSafeDivide(1, 0) %> <SCRIPT LANGUAGE="VBScript" RUNAT=Server> Sub DoSafeDivide(x, y) Dim z On Error Resume Next z = x / y If Err.Number > 0 Then Call Response.Write("Division failed: " & x & " / " & y & "<BR>") Call Response.Write("Error source: " & Err.Source & "<BR>") Call Response.Write("Error number: " & Err.Number & "<BR>") Call Response.Write("Error description: " & Err.Description & "<BR>") Err.Clear Else Call Response.Write("Division succeeded: " & x & " / " & y & " = " & z & "<BR>") End If End Sub </SCRIPT> </HTML>
You can use the For...Each statement to iterate over a collection, thus simplifying your debugging process by returning all of the variables of a collection in a script. For example, the following script sample uses the For...Each statement with the QueryString collection of the Request Object to return values of the QueryString collection.
<TITLE><Query String></TITLE> <% For Each Key In Request.QueryString %> <% = Key %> = <% = Request.QueryString(Key) %><br> <% ValueCount = Request.QueryString(Key).Count If ValueCount > 1 Then %> There are <% = ValueCount %> values for <% = Key %>.<br> <% For i = 1 To ValueCount %> Value <% = i %> is <b><% = Request.QueryString(Key)(i) %></b><br> <% Next End If Next %>
VBScript runtime errors generate a pointer which indicates the exact location of the error in the script code:
if (Request.QueryString ("name") = " " then ------------------------------------^
The following scripting mistakes commonly result in errors for JScript:
Always check for these types of errors when debugging in JScript.
If you are receiving variables in the Request.QueryString collection that should be in the Request.Form collection, make
sure that the HTML<FORM>
tag is setting METHOD=POST
. The GET
method passes form variables into the Request.QueryString
collection. The POST
method passes form variables into the Request.Form collection.