In VBScript, there is an on Error Resume Next statement that causes the script interpreter to ignore Run-time errors and continue the execution of script code. The script can then check the value of the Err.Number property to determine if an error has occurred. If an error occurs, returns a value other than 0. In ASP3.0, you can also use OnErrorGoto0 to "go back" to the default error handling. This process is actually done in ASP2.0, but there is no documentation, which is common in many ASP data-related processing files, plus on Error Resume Next, turning off default error handling and then grabbing with err.
If Err Then
err.Clear
Response.Write "出现了错误!"
Response.End
End If
To get a more detailed description of the error, let's try the ASPError object, which is a new object of asp3.0, which can be obtained through the GetLastError method of the server object, ASPError provides details about the last error that occurred in the ASP, Unlike the Err object in VBScript, the method cannot be invoked at any time to see if an error occurs, but can only be used in an ASP-customized error Web page. If, as with the Err object, the GetLastError method cannot access the details of the error by turning off the default error handling (with the On Error Resume Next statement).
Properties of the ASPError object:
The ASPError object provides nine properties that describe the nature and source of the error that occurred, and returns the actual code that caused the error, with attributes and descriptions as follows:
ASPCode: Integral type. The error number produced 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 cookies and other reports.
Category: String type. The source of the error is the ASP internal scripting language, or an object.
Column: Integral type. The character position in the file where the error occurred
Description: String type. Short description of the error
File: String type. The name of the file being processed when the error occurred
Line: Integral type. The line number in the file that generated the error
Number: integral type. A standard COM error code
Source: String type. Actual code of the row that raised the error
OK, this is 9 attributes, the syntax for 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 ()
A custom error page is loaded when an ASP-related error occurs on any page under all directories supported by IIS (or: In the directory where the error mapping attribute is edited). In fact, a normal scripting error trap is now set, because the ASP run-time errors on any Web page in this directory will trigger a custom error page, the error Web page, which is the default installation part of IIS, can be customized according to your personal circumstances. For example, when we enter a page that does not exist under a directory, A 404 error occurred and when a 404 error occurred, the page used was 404b.htm, which contains a portion of the client script code that obtains the URL of the current document (retrieved from the URL property of the Document object) and displays it in the page:
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 3.2 final//en" >
<style> a:link {font:9pt/11pt color:ff0000} a:visited {font:9pt/11pt song body; color: #4e4e4e}
</style>
<meta name= "ROBOTS" content= "NOINDEX" >
<title> Unable to find page </title>
<meta http-equiv= "Content-type" content= "text-html; charset=gb2312 ">
<meta name= "MS. LOCALE "content=" ZH-CN ">
<script>
function homepage () {
<!--
In real bits, URL get returned to We script like this:
Res://shdocvw.dll/http_404.htm#http://www.docurl.com/bar.htm
For testing Use Docurl = "res://shdocvw.dll/http_404.htm#https://www.microsoft.com/bar.htm"
Docurl = document. URL;
This is where the HTTP or https'll is, as found by searching for://But skipping the res://
Protocolindex=docurl.indexof ("://", 4);
This finds the ending slash for the domain server
Serverindex=docurl.indexof ("/", Protocolindex + 3);
For the HREF, we are need a valid URL to the domain. We Search for the ' # symbol to find the begining
The true URL, and add 1 to skip It-this is the Beginurl value. We use Serverindex as the end marker.
Urlresult=docurl.substring (Protocolindex-4,serverindex);
Beginurl=docurl.indexof ("#", 1) + 1;
Urlresult=docurl.substring (Beginurl,serverindex);
For display, we need to skip http://, and go to the next slash
Displayresult=docurl.substring (Protocolindex + 3, serverindex);
Insertelementanchor (Urlresult, Displayresult);
}
function HtmlEncode (text)
{
Return Text.replace (/&/g, ' & '). Replace (/'/g, ' " '). Replace (/</g, ' < '). Replace (/>/g, ' > ');
}
function Tagattrib (name, value)
{
Return ' +name+ ' = ' +htmlencode ' (value) + ' ";
}
function PrintTag (tagName, Needclosetag, attrib, inner) {
document.write (' < ' + tagName + attrib + ' > ' + HtmlEncode (inner));
if (Needclosetag) document.write (' </' + tagName + ' > ');
}
function URI (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, '; ');
}
function insertelementanchor (href, text)
{
PrintTag (' A ', True, Tagattrib (' href ', URI (HREF)), text);
}
-->
</script>
<body bgcolor= "FFFFFF" >
<table width= "410" cellpadding= "3" cellspacing= "5" >
<tr>
<TD align= "left" valign= "Middle" width= "360" >
</tr>
<tr>
<TD width= "colspan=" 2 "> <font style=" color:000000; font:9pt/11pt Song Body ">
<p> Please try the following actions:</p>
<ul>
<li> If you type the address of the Web page in the Address field, 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 for a link to the information you want. </li>
<li> Click <a href= "Javascript:history.back (1)" > Back </a> button to try other links. </li>
</ul>
<p> Technical information (support for individuals) </p>
<ul>
<li> Details: <br><a href= "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>