|
源代码网推荐
源代码网整理以下 在VBScript中,有一个On Error Resume Next语句,它使脚本解释器忽略运行期错误并继续脚本代码的执行。接着该脚本可以检查Err.Number属性的值,判别是否出现了错误。如果出现错误,返回一个非零值。在ASP 3.0中,也可以使用On Error Goto 0“转回到”缺省的错误处理。在ASP 2.0中实际也进行这种处理,但是没有相应文档说明,这在很多asp数据相关处理文件中司空见惯,加上On Error Resume Next ,关闭缺省的错误处理,然后用err抓住,
源代码网整理以下
|
源代码网整理以下以下为引用的内容:
If Err Then err.Clear Response.Write "出现了错误!" Response.End End If |
源代码网整理以下为了得到更加详细的错误说明,我们就试试asperror对象吧,它是asp3.0的新对象,它可以通过server对象的getlasterror方法得到,asperror提供了关于asp中发生最后一个错误的详细信息,与VBScript的Err对象不同,不能为查看是否出现了错误而随时调用该方法,只能在一个ASP定制的错误网页中使用。如果像对Err对象进行操作那样,通过关闭缺省的错误处理(用On Error Resume Next语句)来使用,则GetLastError方法不能访问错误的详细数据。 ASPError对象的属性: ASPError对象提供了九个属性说明所出现的错误的性质和错误源,并返回引发错误的实际代码,其属性及说明如下:
ASPCode : 整型。由ASP/IIS产生的错误号,例如0x800A009 ASPDescription: 字符串型。如果这个错误是与ASP相关的错误,这个属性是错误的详细说明.例如:All HTTP: HTTP_ACCEPT:*/* HTTP_ACCEPT_LANGUAGE:zh-cn HTTP_CONNECTION:Keep-Alive HTTP_HOST:s HTTP_USER_AGENT:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; (R1 1.5)) ...还有cookie等报告. Category : 字符串型。错误来源,即ASP内部脚本语言、或一个对象. Column : 整型。产生错误的文件中的字符位置 Description : 字符串型。错误的简短说明 File : 字符串型。错误出现时正在处理的文件的名称 Line : 整型。产生错误的文件中的行号 Number : 整型。一个标准的COM错误代码 Source : 字符串型。引发错误的行的实际代码
ok,这就是9个属性,使用asperror对象的语法是:
源代码网整理以下
|
源代码网整理以下以下为引用的内容:
asperror.property 就是这样:ASPError.ASPCode() ASPError.ASPDescription() ASPError.Category() ASPError.Column() ASPError.Description() ASPError.File() ASPError.Line() ASPError.Number() ASPError.Source() |
源代码网整理以下 在iis支持的所有目录下面(或:在编辑了错误映射属性的目录内)的任一页面上出现一个与ASP相关的错误时,都将载入定制错误页面。实际上,现在已经设置了一个正常的脚本错误陷阱,因为在这个目录内的任何一个网页上的ASP运行期错误都将触发定制错误页面,错误网页作为IIS的缺省安装部分,可根据个人情况定制.例如,当我们在一个目录下面输入不存在的网页时,出现404错误,当一个404错误出现时,使用的页面是404b.htm,这个文件包含一个客户端脚本代码部分,它获得当前文档的URL(从document对象的url属性中检索)并在该页面中显示:[html]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <html dir=ltr>
<head> <style> a:link {font:9pt/11pt 宋体; color:FF0000} a:visited {font:9pt/11pt 宋体; color:#4e4e4e} </style>
<META NAME="ROBOTS" CONTENT="NOINDEX">
<title>无法找到网页</title>
<META HTTP-EQUIV="Content-Type" Content="text-html; charset=gb2312"> <META NAME="MS.LOCALE" CONTENT="ZH-CN"> </head>
<script> function Homepage(){ <!-- // in real bits, urls get returned to our 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 will be, 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 need a valid URL to the domain. We search for the # symbol to find the begining //of 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 after 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"> <h1 style="COLOR:000000; FONT: 12pt/15pt 宋体"><!--Problem-->无法找到网页</h1> </td> </tr>
<tr> <td width="400" colspan="2"> <font style="COLOR:000000; FONT: 9pt/11pt 宋体">您正在搜索的网页可能已经删除、更名或暂时不可用。</font></td> </tr>
<tr> <td width="400" colspan="2"> <font style="COLOR:000000; FONT: 9pt/11pt 宋体">
<hr color="#C0C0C0" noshade>
<p>请尝试下列操作:</p>
<ul> <li>如果您在“地址”栏中键入了网页地址,请检查其拼写是否正确。<br> </li>
<li>打开 <script> <!-- if (!((window.navigator.userAgent.indexOf("MSIE") > 0) && (window.navigator.appVersion.charAt(0) == "2"))) { Homepage(); } //--> </script> 主页,寻找指向所需信息的链接。</li>
<li>单击<a href="javascript:history.back(1)">后退</a>按钮尝试其他链接。</li> </ul>
<h2 style="font:9pt/11pt 宋体; color:000000">HTTP 404 - 无法找到文件<br> Internet 信息服务<BR></h2>
<hr color="#C0C0C0" noshade>
<p>技术信息(支持个人)</p>
<ul> <li>详细信息:<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 支持</a> </li> </ul>
</font></td> </tr>
</table> </body> </html> [/html]
源代码网整理以下
源代码网整理以下
源代码网供稿. |