当前位置:首页 > ASP教程 > ASP基础

javascript asp教程错误处理

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 filescommon filessystemadomsado15.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.


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!