捕捉并保存ASP运行错误的函数代码
来源:asp之家 发布时间:2012-11-30 20:24:43
过程名:catch(str)
使用方法:
代码如下:
on error resume next
'你的代码,如数据库连接
call catch("显示给用户的提示信息")
功能:清除IIS的错误提示信息,自定义错误提示返回给用户,并将出错信息保存到txt文件(当然你也可以稍做修改转向自定义页面等)
代码:
代码如下:
<%
option explicit
'例一---------------------------
'必须和on error resume next一起使用,但在网页没有正式发布之前最好将其注释掉,以免在调试时看不到出错详细信息
on error resume next
'i没有定义,会出错,使用catch清除错误并保存到记事本
i
call catch("页面无法访问")
'-------------------------------
'例二---------------------------
function conn()
'必须和on error resume next一起使用
on error resume next
'...........你的连接数据库代码
call catch("数据库打开错误")
end function
'-------------------------------
sub catch(str)
if err.number <> 0 then
dim tmp,path
'错误日志绝对路径,如"/error_log.txt"
path = "/table/error_log.txt"
tmp = tmp & "出错页面:" & geturl & vbcrlf
tmp = tmp & "错误时间:" & now() & vbcrlf
tmp = tmp & "来访IP:" & ip & vbcrlf
tmp = tmp & "提示信息:" & str & vbcrlf
tmp = tmp & "错误代号:" & err.number & vbcrlf
tmp = tmp & "错误信息:" & err.description & vbcrlf
tmp = tmp & "应用程序:" & 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所用到的函数--------------------
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
'获取当前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
'函数:读取文件内容到字符串
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 '文本类型
.mode = 3 '读写模式
.charset = "gb2312"
.open
.loadfromfile(server.MapPath(path))
tmp = .readtext()
end with
stream.close : set stream = nothing
file_read = tmp
end function
'函数:保存字符串到文件
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 '文本类型
.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
'函数:检测文件/文件夹是否存在
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
%>


猜你喜欢
- 前言:内容提要:本文比较了 Python 中用于列表排序的两种函数 sort() 和 sorted(),帮助您选择合适的排序函数。对列表排序
- bookheader.asp Recommended Books for <%=session(&quo
- python语句mode = ‘test’ if y is None else &lsquo
- Bootstrap 通过一些简单的 HTML 标签和扩展的类即可创建出不同样式的表单。0x01 样式1一个登录界面:<!DOCTYPE
- 0. 学习目标栈和队列是在程序设计中常见的数据类型,从数据结构的角度来讲,栈和队列也是线性表,是操作受限的线性表,它们的基本操作是线性表操作
- 本文主要介绍了MySQL8.0.27安装过程中卡在Initializing Database中并报错的解决,具有一定的参考价值,具体如下:报
- 其实所有的死锁最深层的原因就是一个:资源竞争。表现一:一个用户A 访问表A(锁住了表A),然后又访问表B
- 使用Pyinstaller打包整个项目今天真的被Pyinstaller给坑到了!!!本文利用spec文件进行对整个项目进行打包,直接输入命令
- 业务场景:前后端分离需要对接数据接口。接口测试是在postman做的,今天才开始和前端对接,由于这是我第一次做后端接口开发(第一次嘛,问题比
- 之前折磨了很久,想在Mysql命令行下导出数据库,但就是每天提示不那个错误,后来才知道其实mysqldump不是mysql命令,因此不能在M
- Django是一个开放源代码的Web应用框架,由Python写成。采用了MTV的框架模式,即模型M,视图V和模版T。它最初是被开发来用于管理
- XML 的使用越来越广泛,但是很多 XML 的结构并不好。即便结构良好,也常常设计得很糟,使得处理和维护非常困难。而大部分用于 XML 的基
- 监控中,通常要使用图片更直观的看出集群的运行状况。以下是一个简单的demo,通过rrdtool生成动态的图片。Python3, tornad
- 上一节除了介绍使用 Python 连接 es,还有最简单的 query() 方法,这一节介绍一下几种其他的查询方式。1、query() 方法
- 雅虎的BrowserPlus在曝光了N久后终于发布了,一款类似于Google Gears的浏览器增强插件。在支持的操作系统方面,Gears明
- 一、命令提示符窗口安装卸载1、安装第一种,最常用的,初学者也是基本都是用的这个方法,直接在cmd里面安装。首先键盘按住win+r就会弹出来运
- 本文实例讲述了Python3实现从文件中读取指定行的方法。分享给大家供大家参考。具体实现方法如下:# Python的标准库linecache
- 又一个js加密工具:js混淆,完整源代码如下,有点长呵呵:<HTML><HEAD><TITLE>Cunf
- 前言日志收集项目的准备中,本文主要讲的是利用golang的tail库,监听日志文件的变动,将日志信息发送到kafka中。涉及的golang库
- Usuage: go run kNN.go --file="data.txt"关键是向量点的选择和阈值的判定