javascript asp教程错误处理

所属分类: 网络编程 / ASP编程 阅读数: 704
收藏 0 赞 0 分享

The ASPError Object has zero (0) Methods, nine (9) Properties, zero (0) Events, and zero (0) Collections.

AspCode
AspDescription
Category
Column
Description
File
Line
Number
Source

The way you access the ASPError Properties is with a Server Method. Yeah, I know; it doesn't make sense. Start with something like var myError=Server.GetLastError() and then you can access all nine ASPError Properties following this pattern: <%=myError.Line%>.

Below is the script for Lesson 15.

<%@LANGUAGE="JavaScript"%>
<!-- METADATA TYPE="typelib" 
FILE="C:\Program Files\Common Files\System\ado\msado15.dll" -->
<%
try
	{
	Response.Write("<STRONG>Use <I>GetLastError( )</I><BR></STRONG>\r")
	myError = Server.GetLastError()
	Response.Write("myError.Line: " + myError.Line + "<BR>\r")
	Response.Write("myError.File: " + myError.File + "\r")
	Response.Write("<HR>\r<STRONG>")
	Response.Write("Now an intentional error...")
	Response.Write("<BR></STRONG>\r")
	myError = erver.GetLastError() //this line causes an error
	Response.Write("myError.Line: " + myError.Line + "<BR>\r")
	Response.Write("myError.File: " + myError.File + "<BR>\r")
	}
catch(myDumbError) 
	{ 
	Response.Write("There is an error: " + myDumbError)
	%>
	<BR>
	Graceful error handling goes here (inside the catch statement).
	Make it as simple or sophisticated as you like.<BR>
	<HR>
	<STRONG>Now let's break down the error Object.</STRONG><BR>
	<%
	for ( var i in myDumbError)
		{
		Response.Write(i + ": " + myDumbError[i] + "<BR>\r")
		}
	}
finally
	{
	Response.Write("<HR><STRONG>Let's Finish Up.</STRONG><BR>\r")
	Response.Write("Code inside the <I>finally { }</I> statement ")
	Response.Write("executes regardless of error (or lack thereof). \r")
	Response.Write("<I>finally{ }</I> is totally optional. ")
	Response.Write("It's a good place for things like RS.Close()... ")
	Response.Write("which you'll see later on.")
	}
%>

Click Here to run the script in a new window.

Okay, so what happened to On Error Resume Next? Sorry, that ain't no JavaScript thing. So, what about onerror? That won't work on the server side. But thanks to some core JavaScript we have some error handling.

The section of script for which you wish to provide error handling goes inside the try { } statements and the what-to-do in the event of an error goes inside the catch { } statement. There is also a finally { } statement (optional). The whole thing is just as graceful as On Error (in my opinion).

Not every ASP server allows you access to the ASPError Object. So, don't be surprised if ASPError gives you an error.

更多精彩内容其他人还在看

ASP编程入门进阶(廿一):DAO SQL之建立数据库表

ASP编程入门进阶(廿一):DAO SQL之建立数据库表
收藏 0 赞 0 分享

ASP万用分页程序

这只是个asp小技巧类的东西,它虽然适合在每个不同文件名里调用这个函数,但是也是有前提的,下面让我们来仔细看看其中的原委
收藏 0 赞 0 分享

ASP项目中的公共翻页模块

ASP项目中的公共翻页模块
收藏 0 赞 0 分享

asp实现批量录入数据的实现

asp实现批量录入数据的实现
收藏 0 赞 0 分享

从文本文件中读取信息并存储入数据库

从文本文件中读取信息并存储入数据库
收藏 0 赞 0 分享

在ASP中使用均速分页法提高分页速度

在ASP中使用均速分页法提高分页速度
收藏 0 赞 0 分享

一些值得一看的代码asp

这篇文章主要介绍了一些值得一看的代码asp
收藏 0 赞 0 分享

3种不同的方法生成文件

3种不同的方法生成文件
收藏 0 赞 0 分享

校验算法与ASP程序

这篇文章主要介绍了校验算法与ASP程序
收藏 0 赞 0 分享

ASP抽取数据的执行效率

ASP抽取数据的执行效率
收藏 0 赞 0 分享
查看更多