统计在线人数...

浅谈asp编程中的测试打印、有效性检查及错误处理

[ 来源:ASP教程 | 作者:Admin | 时间:2004-9-2 上午 01:09:25 | 浏览:统计中... ]

) + Chr(10)
strLogMsg = strLogMsg + "错误时间:" + CStr(Now()) + Chr(13) + Chr(10)
strLogMsg = strLogMsg + "错误类型:Err错误" + Chr(13) + Chr(10)
strLogMsg = strLogMsg + "错误号 :" + CStr(Err.Number) + Chr(13) + Chr(10)
strLogMsg = strLogMsg + "错误源 :" + Err.Source + Chr(13) + Chr(10)
strLogMsg = strLogMsg + "错误描述:" + Err.Description + Chr(13) + Chr(10)
strLogMsg = strLogMsg + "*********************************************************************************************" + Chr(13) + Chr(10)

'清空Err
Err.Clear

'在Redirect之前写日志
WriteLog(strLogMsg)

strMsg = Server.UrlEncode(strMsg)
'如果是调试则显示错误代码
if Application("DEBUG") = 1 then
Response.Redirect("../include/error.asp?" + _
"ErrText="&strMsg&"")
else
Response.Redirect("../include/error.asp")
end if

'如果是程序错误,则写日志
else

strMsg = strMsg + "*********************************************************************************************" + "<BR>"
strMsg = strMsg + "错误时间:" + CStr(Now()) + "<BR>"

strLogMsg = strLogMsg + "*********************************************************************************************" + Chr(13) + Chr(10)
strLogMsg = strLogMsg + "错误时间:" + CStr(Now()) + Chr(13) + Chr(10)

Dim strWhichErr
Select Case a_intErrCode

Case 99001 '程序错误从99001开始
strWhichErr = "断言错误"
Case 99002
strWhichErr = "Case Else 错误"
Case else
strWhichErr = "未知的错误"
End Select

strMsg = strMsg + "错误类型:" + strWhichErr + "<BR>"
if a_strErrText <> "" then
strMsg = strMsg + "错误描述:" + a_strErrText + "<BR>"
end if
strMsg = strMsg + "*********************************************************************************************" + "<BR>"

strLogMsg = strLogMsg + "错误类型:" + strWhichErr + Chr(13) + Chr(10)
if a_strErrText <> "" then
strLogMsg = strLogMsg + "错误描述:" + a_strErrText + Chr(13) + Chr(10)
end if
strLogMsg = strLogMsg + "*********************************************************************************************" + Chr(13) + Chr(10)

'写日志
WriteLog(strLogMsg)

'如果是调试状态则指向错误页
if Application("DEBUG") = 1 then
strMsg = Server.UrlEncode(strMsg)
Response.Redirect("http://server1/4biz/include/error.asp?" + _
"ErrText="&strMsg&"")
end if
end if
End Sub


'--------------------------------------------------------
'Name: WriteLog
'Argument: a_strMsg:日志内容
'Return:
'Description: 错误处理
'Hitory: Create by Yaozhigang
'--------------------------------------------------------
Function WriteLog(a_strMsg)
Dim strFileName

if Application("g_strLogFileName") = "" then
strFileName = "c:\AspLog.txt"
else
strFileName = Application("g_strLogFileName")
end if

Dim objFSO
Dim objFile
Set objFSO = CreateObject("Scripting.FileSystemObject")

'只有一个人写日志
Application.Lock

Set objFile = objFSO.OpenTextFile(strFileName, 8, True, 0)
objFile.Write(a_strMsg)
objFile.Close

Application.UnLock

Set objFile = Nothing
Set objFSO = Nothing
End Function

以上几个函数及过程的作用是处理数据库错误,注意使用时在global.asp里加上on eroor resume,以使错误处理程序能够运行。其中可以显示错误代码、写日志文件,详细内容我就不做解释了,请自己研究一下源代码。
(出处:热点网络)

上一页  [1] [2] 

共有0人参与评价,平均得分:0分
评论内容只代表网友观点,与本站立场无关! 查看完整内容
   

当前在线人数
QQ:748838 MSN:allen_xia#msn.com E-mail:allenxia666#126.com QQ群:站长联盟北方区-北京(28200145) 站长联盟南方区-上海(67713522)