佳木斯湛栽影视文化发展公司

主頁(yè) > 知識(shí)庫(kù) > 捕捉并保存ASP運(yùn)行錯(cuò)誤的函數(shù)代碼

捕捉并保存ASP運(yùn)行錯(cuò)誤的函數(shù)代碼

熱門(mén)標(biāo)簽:銀行業(yè)務(wù) 阿里云 Mysql連接數(shù)設(shè)置 服務(wù)器配置 科大訊飛語(yǔ)音識(shí)別系統(tǒng) 電子圍欄 團(tuán)購(gòu)網(wǎng)站 Linux服務(wù)器
過(guò)程名:catch(str)
使用方法:
復(fù)制代碼 代碼如下:

on error resume next
'你的代碼,如數(shù)據(jù)庫(kù)連接
call catch("顯示給用戶(hù)的提示信息")

功能:清除IIS的錯(cuò)誤提示信息,自定義錯(cuò)誤提示返回給用戶(hù),并將出錯(cuò)信息保存到txt文件(當(dāng)然你也可以稍做修改轉(zhuǎn)向自定義頁(yè)面等)

代碼:
復(fù)制代碼 代碼如下:

%
option explicit
'例一---------------------------
'必須和on error resume next一起使用,但在網(wǎng)頁(yè)沒(méi)有正式發(fā)布之前最好將其注釋掉,以免在調(diào)試時(shí)看不到出錯(cuò)詳細(xì)信息
on error resume next
'i沒(méi)有定義,會(huì)出錯(cuò),使用catch清除錯(cuò)誤并保存到記事本
i
call catch("頁(yè)面無(wú)法訪問(wèn)")
'-------------------------------
'例二---------------------------
function conn()
'必須和on error resume next一起使用
on error resume next
'...........你的連接數(shù)據(jù)庫(kù)代碼
call catch("數(shù)據(jù)庫(kù)打開(kāi)錯(cuò)誤")
end function
'-------------------------------
sub catch(str)
if err.number > 0 then
dim tmp,path
'錯(cuò)誤日志絕對(duì)路徑,如"/error_log.txt"
path = "/table/error_log.txt"
tmp = tmp "出錯(cuò)頁(yè)面:" geturl vbcrlf
tmp = tmp "錯(cuò)誤時(shí)間:" now() vbcrlf
tmp = tmp "來(lái)訪IP:" ip vbcrlf
tmp = tmp "提示信息:" str vbcrlf
tmp = tmp "錯(cuò)誤代號(hào):" err.number vbcrlf
tmp = tmp "錯(cuò)誤信息:" err.description vbcrlf
tmp = tmp "應(yīng)用程序:" err.source vbcrlf vbcrlf vbcrlf
tmp = tmp file_read(path)
call file_save(tmp,path,1)
err.clear()
die(str)
end if
end sub
'以下為catch所用到的函數(shù)--------------------
sub echo(str)
response.write(str)
end sub
sub die(str)
echo(str) : response.end()
end sub
function ip()
ip = request.servervariables("remote_addr")
end function
'獲取當(dāng)前URL
function geturl()
dim tmp
if lcase(request.servervariables("https")) = "off" then
tmp = "http://"
else
tmp = "https://"
end if
tmp = tmp request.servervariables("server_name")
if request.servervariables("server_port") > 80 then
tmp = tmp ":" request.servervariables("server_port")
end if
tmp = tmp request.servervariables("url")
if trim(request.querystring) > "" then
tmp = tmp "?" trim(request.queryString)
end if
geturl = tmp
end function
'函數(shù):讀取文件內(nèi)容到字符串
function file_read(path)
dim tmp : tmp = "false"
if not file_exists(path) then file_read = tmp : exit function
dim stream : set stream = server.CreateObject("ADODB.Stream")
with stream
.type = 2 '文本類(lèi)型
.mode = 3 '讀寫(xiě)模式
.charset = "gb2312"
.open
.loadfromfile(server.MapPath(path))
tmp = .readtext()
end with
stream.close : set stream = nothing
file_read = tmp
end function
'函數(shù):保存字符串到文件
function file_save(str,path,model)
if model>0 and model>1 then model=1
if model=0 and file_exists(path) then file_save=true : exit function
dim stream : set stream = server.CreateObject("ADODB.Stream")
with stream
.type = 2 '文本類(lèi)型
.charset = "gb2312"
.open
.writetext str
.savetofile(server.MapPath(path)),model+1
end with
stream.close : set stream = nothing
file_save = file_exists(path)
end function
'函數(shù):檢測(cè)文件/文件夾是否存在
function file_exists(path)
dim tmp : tmp = false
dim fso : set fso = server.CreateObject("Scripting.FilesyStemObject")
if fso.fileexists(server.MapPath(path)) then tmp = true
if fso.folderexists(server.MapPath(path)) then tmp = true
set fso = nothing
file_exists = tmp
end function
%>

標(biāo)簽:廣元 衢州 蚌埠 江蘇 衡水 棗莊 大理 萍鄉(xiāng)

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《捕捉并保存ASP運(yùn)行錯(cuò)誤的函數(shù)代碼》,本文關(guā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)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話(huà)咨詢(xún)

    • 400-1100-266
    睢宁县| 玛纳斯县| 博白县| 维西| 临泉县| 三明市| 绥棱县| 资兴市| 天长市| 丰宁| 西峡县| 峨山| 怀宁县| 万源市| 阳城县| 弋阳县| 龙里县| 彩票| 德钦县| 天水市| 达拉特旗| 霞浦县| 普兰店市| 建德市| 广丰县| 徐汇区| 鄂伦春自治旗| 通州区| 临安市| 策勒县| 江西省| 棋牌| 汶川县| 长泰县| 安岳县| 珲春市| 平安县| 龙海市| 广水市| 饶平县| 沐川县|