网络编程
位置:首页>> 网络编程>> Asp编程>> ASPError(err)对象的相关基础知识(3)

ASPError(err)对象的相关基础知识(3)

作者:5do8  发布时间:2008-03-24 20:23:00 

标签:Error,Err.Number,错误,asp

如果原ASP网页正在一个事务内运行,即在网页的最前面包含有一个<%@TRANSACTION=”…”%>指令,也应该确定是否需要在网页中采取一些方法,以退出该事务。例如可以调用内置ObjectContext对象的SetAbort方法:

objectContext.SetAbort

嗯,前端时间发过几千垃圾邮件,全是错误处理的


OptionExplicit
Response.AddHeader"StatusCode","200"
Response.AddHeader"Reason","OK"
OnErrorResumeNext
Response.Clear
DimobjError
SetobjError=Server.GetLastError()
dimobjErr,objMail,html
setobjErr=Server.GetLastError()
SetobjMail=CreateObject("CDONTS.NewMail")
objMail.From="s1z2d3s1@163.com"
objMail.to="5do8@5do8.com"
objMail.BodyFormat=0
objMail.MailFormat=0
objMail.Subject="QOPError500"
html="<fontface='Verdana,Arial,Helvetica,sans-serif'><br>"
html=html&"<p>Erroroccuredat:"&now
html=html&"<p>Referredfrom:"&request.ServerVariables("HTTP_REFERER")
html=html&"<p>Url:"&request.ServerVariables("URL")
html=html&"<p><b>Category:</b></p>"&objErr.Category
html=html&"<p><b>Filename:</b></p>"&objErr.File
html=html&"<p><b>ASPCode:</b></p>"&objErr.ASPCode
html=html&"<p><b>Number:</b></p>"&objErr.Number
html=html&"<p><b>Source:</b></p>"&objErr.Source
html=html&"<p><b>LineNumber:</b></p>"&objErr.Line
html=html&"<p><b>Column:</b></p>"&objErr.Column
html=html&"<p><b>Description:</b></p>"&objErr.Description
html=html&"<p><b>ASPDescription:</b></p>"&objErr.ASPDescription
html=html&"<blockquote>"
html=html&"AllHTTP:"&Request.ServerVariables("ALL_HTTP")
html=html&"</blockquote></font>"
objMail.Body=html
objMail.Send
objErr.clear
SetobjMail=Nothing
SetobjErr=Nothing
response.write(html)

这个操作起来确实很烦,看看老盖先生的在500-100.asp里面写了写什么东西:


<%
 Response.WriteobjASPError.Category
 IfobjASPError.ASPCode>""ThenResponse.Write","&objASPError.ASPCode
 Response.Write"(0x"&Hex(objASPError.Number)&")"&"<br>"
 Response.Write"<b>"&objASPError.Description&"</b><br>"
 IfobjASPError.ASPDescription>""ThenResponse.WriteobjASPError.ASPDescription&"<br>"
 blnErrorWritten=False
 'OnlyshowtheSourceifitisavailableandtherequestisfromthesamemachineasIIS
 IfobjASPError.Source>""Then
strServername=LCase(Request.ServerVariables("SERVER_NAME"))
strServerIP=Request.ServerVariables("LOCAL_ADDR")
strRemoteIP= Request.ServerVariables("REMOTE_ADDR")
If(strServername="localhost"OrstrServerIP=strRemoteIP)AndobjASPError.File<>"?"Then
 Response.WriteobjASPError.File
 IfobjASPError.Line>0ThenResponse.Write",line"&objASPError.Line
 IfobjASPError.Column>0ThenResponse.Write",column"&objASPError.Column
 Response.Write"<br>"
 Response.Write"<fontstyle=""COLOR:000000;FONT:8pt/11ptcouriernew""><b>"
 Response.WriteServer.HTMLEncode(objASPError.Source)&"<br>"
 IfobjASPError.Column>0ThenResponse.WriteString((objASPError.Column-1),"-")&"^<br>"
 Response.Write"</b></font>"
 blnErrorWritten=True
EndIf
 EndIf
 IfNotblnErrorWrittenAndobjASPError.File<>"?"Then
Response.Write"<b>"&objASPError.File
IfobjASPError.Line>0ThenResponse.Write",line"&objASPError.Line
IfobjASPError.Column>0ThenResponse.Write",column"&objASPError.Column
Response.Write"</b><br>"
 EndIf
%>

此处参考了:ASP3.0高级编程关于使用ASPError对象的属性,有以下几点值得注意的:

·即使没有出现错误,Number属性应该一直有一个值。如果ASP网页调用GetLastError方法时没有错误出现,该属性的值是0。通常情况下,对ASP脚本的运行期错误,Number属性返回十六进制的值“0x800A0000”,加上标准的脚本引擎错误代码。例如,前面的例子对“SubscriptoutofRange”错误的返回值为“0x800A0009”,因为VBScript对该类型错误的错误代码是“9”。

·当出现已经过一个错误时,Category和Description属性将一直有一个值。

·APSCode属性的值由IIS产生,对大多数脚本错误将为空。更多情况下,涉及外部组件使用出错时有相应的值。

·ASPDescription属性的值由ASP预处理程序产生,而不是由当前正在使用的脚本引擎产生的,并且对大多数脚本错误而言将是空的。更多情况下,对诸如对ASP内置对象调用无效的方法的错误有相应的值。

·File、Source、Line和column属性仅在错误出现时,并且在错误的详细数据是可用的情况下才能进行设置。对一个运行期错误,File和Line属性通常是有效的,但是column属性经常返回-1。当错误是一个阻止页面被ASP处理的语法错误,才返回Source属性。一般在这些情况下,Line和Column属性是有效的。如果把Source属性的值写到页面,明智的办法是先将该值传给HTMLEncode,以防在其含有非法的HTML字符。在本章的后面将详细地讨论HTMLEncode方法.

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com