在VBScript中,有一個(gè)On Error Resume Next語(yǔ)句,它使腳本解釋器忽略運(yùn)行期錯(cuò)誤并繼續(xù)腳本代碼的執(zhí)行。接著該腳本可以檢查Err.Number屬性的值,判別是否出現(xiàn)了錯(cuò)誤。如果出現(xiàn)錯(cuò)誤,返回一個(gè)非零值。在ASP3.0中,也可以使用OnErrorGoto0“轉(zhuǎn)回到”缺省的錯(cuò)誤處理。在ASP2.0中實(shí)際也進(jìn)行這種處理,但是沒(méi)有相應(yīng)文檔說(shuō)明,這在很多asp數(shù)據(jù)相關(guān)處理文件中司空見(jiàn)慣,加上On Error Resume Next,關(guān)閉缺省的錯(cuò)誤處理,然后用err抓住,
If Err Then err.Clear Response.Write "出現(xiàn)了錯(cuò)誤!" Response.End End If
為了得到更加詳細(xì)的錯(cuò)誤說(shuō)明,我們就試試asperror對(duì)象吧,它是asp3.0的新對(duì)象,它可以通過(guò)server對(duì)象的getlasterror方法得到,asperror提供了關(guān)于asp中發(fā)生最后一個(gè)錯(cuò)誤的詳細(xì)信息,與VBScript的Err對(duì)象不同,不能為查看是否出現(xiàn)了錯(cuò)誤而隨時(shí)調(diào)用該方法,只能在一個(gè)ASP定制的錯(cuò)誤網(wǎng)頁(yè)中使用。如果像對(duì)Err對(duì)象進(jìn)行操作那樣,通過(guò)關(guān)閉缺省的錯(cuò)誤處理(用On Error Resume Next語(yǔ)句)來(lái)使用,則GetLastError方法不能訪(fǎng)問(wèn)錯(cuò)誤的詳細(xì)數(shù)據(jù)。
ASPError對(duì)象的屬性:
ASPError對(duì)象提供了九個(gè)屬性說(shuō)明所出現(xiàn)的錯(cuò)誤的性質(zhì)和錯(cuò)誤源,并返回引發(fā)錯(cuò)誤的實(shí)際代碼,其屬性及說(shuō)明如下:
ASPCode:整型。由ASP/IIS產(chǎn)生的錯(cuò)誤號(hào),例如0x800A009
ASPDescription: 字符串型。如果這個(gè)錯(cuò)誤是與ASP相關(guān)的錯(cuò)誤,這個(gè)屬性是錯(cuò)誤的詳細(xì)說(shuō)明.例如: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))...還有cookie等報(bào)告.
Category:字符串型。錯(cuò)誤來(lái)源,即ASP內(nèi)部腳本語(yǔ)言、或一個(gè)對(duì)象.
Column:整型。產(chǎn)生錯(cuò)誤的文件中的字符位置
Description:字符串型。錯(cuò)誤的簡(jiǎn)短說(shuō)明
File:字符串型。錯(cuò)誤出現(xiàn)時(shí)正在處理的文件的名稱(chēng)
Line:整型。產(chǎn)生錯(cuò)誤的文件中的行號(hào)
Number:整型。一個(gè)標(biāo)準(zhǔn)的COM錯(cuò)誤代碼
Source:字符串型。引發(fā)錯(cuò)誤的行的實(shí)際代碼
ok,這就是9個(gè)屬性,使用asperror對(duì)象的語(yǔ)法是:
asperror.property
就是這樣:
ASPError.ASPCode()
ASPError.ASPDescription()
ASPError.Category()
ASPError.Column()
ASPError.Description()
ASPError.File()
ASPError.Line()
ASPError.Number()
ASPError.Source()
在iis支持的所有目錄下面(或:在編輯了錯(cuò)誤映射屬性的目錄內(nèi))的任一頁(yè)面上出現(xiàn)一個(gè)與ASP相關(guān)的錯(cuò)誤時(shí),都將載入定制錯(cuò)誤頁(yè)面。實(shí)際上,現(xiàn)在已經(jīng)設(shè)置了一個(gè)正常的腳本錯(cuò)誤陷阱,因?yàn)樵谶@個(gè)目錄內(nèi)的任何一個(gè)網(wǎng)頁(yè)上的ASP運(yùn)行期錯(cuò)誤都將觸發(fā)定制錯(cuò)誤頁(yè)面,錯(cuò)誤網(wǎng)頁(yè)作為IIS的缺省安裝部分,可根據(jù)個(gè)人情況定制.例如,當(dāng)我們?cè)谝粋€(gè)目錄下面輸入不存在的網(wǎng)頁(yè)時(shí),出現(xiàn)404錯(cuò)誤,當(dāng)一個(gè)404錯(cuò)誤出現(xiàn)時(shí),使用的頁(yè)面是404b.htm,這個(gè)文件包含一個(gè)客戶(hù)端腳本代碼部分,它獲得當(dāng)前文檔的URL(從document對(duì)象的url屬性中檢索)并在該頁(yè)面中顯示:
!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>無(wú)法找到網(wǎng)頁(yè)/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, 'amp').replace(/'/g, 'quot;').replace(//g, 'lt;').replace(/>/g, 'gt;'); } 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-->無(wú)法找到網(wǎng)頁(yè)/h1> /td> /tr> tr> td width="400" colspan="2"> font style="COLOR:000000; FONT: 9pt/11pt 宋體">您正在搜索的網(wǎng)頁(yè)可能已經(jīng)刪除、更名或暫時(shí)不可用。/font>/td> /tr> tr> td width="400" colspan="2"> font style="COLOR:000000; FONT: 9pt/11pt 宋體"> hr color="#C0C0C0" noshade> p>請(qǐng)嘗試下列操作:/p> ul> li>如果您在“地址”欄中鍵入了網(wǎng)頁(yè)地址,請(qǐng)檢查其拼寫(xiě)是否正確。br> /li> li>打開(kāi) script> !-- if (!((window.navigator.userAgent.indexOf("MSIE") > 0) (window.navigator.appVersion.charAt(0) == "2"))) { Homepage(); } //--> /script> 主頁(yè),尋找指向所需信息的鏈接。/li> li>單擊a href="javascript:history.back(1)">后退/a>按鈕嘗試其他鏈接。/li> /ul> h2 style="font:9pt/11pt 宋體; color:000000">HTTP 404 - 無(wú)法找到文件br> Internet 信息服務(wù)BR>/h2> hr color="#C0C0C0" noshade> p>技術(shù)信息(支持個(gè)人)/p> ul> li>詳細(xì)信息:br>a target="_blank">Microsoft 支持/a> /li> /ul> /font>/td> /tr> /table> /body> /html>
以上就是對(duì)ASP error對(duì)象的全部簡(jiǎn)析,希望對(duì)大家的學(xué)習(xí)有所幫助。
標(biāo)簽:海南 攀枝花 揭陽(yáng) 唐山 鶴崗 撫州 佛山 汕頭
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《ASP的Error對(duì)象知識(shí)簡(jiǎn)析》,本文關(guān)鍵詞 ASP,的,Error,對(duì)象,知識(shí),簡(jiǎn)析,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。