This article mainly introduces the Error object of ASP. Friends who need it can refer to it
In VBScript, there is an On Error Resume Next statement that causes the script interpreter to ignore runtime errors and continue execution of the script code. Then the script can check the value of the Err.Number property to determine whether an error occurred. If an error occurs, a non-zero value is returned. In ASP3.0, you can also use OnErrorGoto0 to go back to the default error handling. This kind of processing is actually performed in ASP2.0, but there is no corresponding document description, which is common in many asp data-related processing files. Add On Error Resume Next, close the default error processing and then catch it with err.
- IfErrThen
- err.Clear
- There is an error in Response.Write!
- Response.End
- EndIf
In order to get a more detailed error description, let's try the asperror object. It is a new object of asp3.0. It can be obtained through the getlasterror method of the server object. Asperror provides detailed information about the last error in asp, and VBScript's Err object is different. This method cannot be called at any time to see if an error occurs. It can only be used in an ASP customized error page. If the default error handling is turned off (using the On Error Resume Next statement) like an Err object, the GetLastError method cannot access the error detailed data.
Properties of ASPError object:
The ASPError object provides nine attributes to indicate the nature and source of the error that occurred, and returns the actual code that caused the error. The properties and descriptions are as follows:
ASPCode: Integer. Error number generated by ASP/IIS, such as 0x800A009
ASPDescription: String type. If this error is an ASP-related error, this property is a detailed description of the error. For example: AllHTTP:HTTP_ACCEPT:*/*HTTP_ACCEPT_LANGUAGE:zh-cnHTTP_CONNECTION:Keep-AliveHTTP_HOST:sHTTP_USER_AGENT:Mozilla/4.0(compatible;MSIE6.0;WindowsNT5 .0;(R11.5)).. There are also reports such as cookies.
Category: String type. The source of the error is that of the ASP internal scripting language, or an object.
Column: Integer. Character location in the file that generated the error
Description: String type. A brief description of the error
File: String type. The name of the file being processed when the error occurred
Line: Integer. Line number in the file that generated the error
Number: Integer. A standard COM error code
Source: String type. The actual code of the line that raised the error
OK, these are 9 properties. The syntax of using the asperror object is:
asperror.property
That's it:
ASPError.ASPCode()
ASPError.ASPDescription()
ASPError.Category()
ASPError.Column()
ASPError.Description()
ASPError.File()
ASPError.Line()
ASPError.Number()
ASPError.Source()
When an ASP-related error occurs on any page under all directories supported by IIS (or in the directory where the error mapping properties are edited), the custom error page will be loaded. In fact, a normal script error trap has been set now, because the ASP runtime error on any web page in this directory will trigger the customized error page. The error page is the default installation part of IIS and can be based on personal circumstances. Customization. For example, when we enter a web page that does not exist in a directory, a 404 error occurs. When a 404 error occurs, the page used is 404b.htm. This file contains a client script code section, which obtains the current document The URL of the document object (retrieved from the url property of the document object) and is displayed in the page:
- <!DOCTYPEHTMLPUBLIC-//W3C//DTDHTML3.2Final//EN>
- <htmldir=ltr>
- <head>
- <style>a:link{font:9pt/11pt安安;color:FF0000}a:visited{font:9pt/11pt安安安安;color:#4e4e4e}
- </style>
- <METANAME=ROBOTSCONTENT=NOINDEX>
- <title>Unable to find the web page</title>
- <METAHTTP-EQUIV=Content-TypeContent=text-html;charset=gb2312>
- <METANAME=MS.LOCALECONTENT=EN-CN>
- </head>
- <script>
- functionHomepage(){
- <!--
- //inrealbits,urlsgetreturnedtoourscriptlikethis:
- //res://shdocvw.dll/http_404.htm#http://www.DocURL.com/bar.htm
- //FortestinguseDocURL=res://shdocvw.dll/http_404.htm#https://www.microsoft.com/bar.htm
- DocURL=document.URL;
- //thisiswherethehttporhttpswillbe,asfoundbysearchingfor://butskippingtheres://
- protocolIndex=DocURL.indexOf(://,4);
- // thisfindstheendingslashforthedomainserver
- serverIndex=DocURL.indexOf(/,protocolIndex+3);
- //forthehref,weneedavalidURLtothedomain.Wesearchforthe#symboltofindthebegining
- //ofthetrueURL,andadd1toskipit-thisisttheBeginURLvalue.WeuseserverIndexastheendmarker.
- //urlresult=DocURL.substring(protocolIndex-4,serverIndex);
- BeginURL=DocURL.indexOf(#,1)+1;
- urlresult=DocURL.substring(BeginURL,serverIndex);
- //fordisplay,weneedtoskipafterhttp://,andgotothenextslash
- displayresult=DocURL.substring(protocolIndex+3,serverIndex);
- InsertElementAnchor(urlresult,displayresult);
- }
- functionHtmlEncode(text)
- {
- returntext.replace(/&/g,'&').replace(/'/g,'').replace(/</g,'<').replace(//g,'>');
- }
- functionTagAttrib(name,value)
- {
- return''+name+'='+HtmlEncode(value)+'';
- }
- functionPrintTag(tagName, needCloseTag,attrib,inner){
- document.write('<'+tagName+attrib+'>'+HtmlEncode(inner));
- if(needCloseTag)document.write('</'+tagName+'>');
- }
- functionURI(href)
- {
- IEVer=window.navigator.appVersion;
- IEVer=IEVer.substr(IEVer.indexOf('MSIE')+5,3);
- return(IEVer.charAt(1)=='.'&&IEVer>='5.5')?
- encodeURI(href):
- escape(href).replace(/%3A/g,':').replace(/%3B/g,';');
- }
- functionInsertElementAnchor(href,text)
- {
- PrintTag('A',true,TagAttrib('HREF',URI(href)),text);
- }
- //-->
- </script>
- <bodybgcolor=FFFFFF>
- <tablewidth=410cellpadding=3cellpacing=5>
- <tr>
- <tdalign=leftvalign=middlewidth=360>
- <h1style=COLOR:000000;FONT:12pt/15pt安安><!--Problem-->The web page cannot be found</h1>
- </td>
- </tr>
- <tr>
- <tdwidth=400colspan=2><fontstyle=COLOR:000000;FONT:9pt/11pt安安>The web page you are searching for may have been deleted, renamed, or is temporarily unavailable. </font></td>
- </tr>
- <tr>
- <tdwidth=400colspan=2><fontstyle=COLOR:000000;FONT:9pt/11pt安安>
- <hrcolor=#C0C0C0noshade>
- <p>Please try the following:</p>
- <ul>
- <li>If you typed a web address in the address bar, check that it is spelled correctly. <br>
- </li>
- <li>Open <script>
- <!--
- if(!((window.navigator.userAgent.indexOf(MSIE)>0)&&(window.navigator.appVersion.charAt(0)==2)))
- {
- Homepage();
- }
- //-->
- </script>Homepage, find links to the required information. </li>
- <li>Click the <ahref=javascript:history.back(1)>Back</a> button to try other links. </li>
- </ul>
- <h2style=font:9pt/11pt安安;color:000000>HTTP404-File cannot be found<br>Internet Information Service<BR></h2>
- <hrcolor=#C0C0C0noshade>
- <p>Technical Information (Supporting Individuals)</p>
- <ul>
- <li>Details: <br><ahref=http://www.microsoft.com/ContentRedirect.asp?prd=iis&sbp=&pver=5.0&pid=&ID=404&cat=web&os=&over=&hrd=&Opt1=&Opt2=&Opt3 =target=_blank>Microsoft Support</a>
- </li>
- </ul>
- </font></td>
- </tr>
- </table>
- </body>
- </html>
The above is a brief analysis of the ASP error object, and I hope it will be helpful to everyone's learning.