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

时间: 2024-09-27 18:24:17

javascript asp教程错误处理的相关文章

javascript asp教程错误处理_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. Y

javascript asp教程添加和修改_ASP基础

The Connection Execute(): If you want to retrieve data from a database then you have no choice but to use a Recordset. However, for the purposes of adding, updating, and deleting data you don't necessarily have to have a Recordset. It's up to you. Fo

javascript asp教程 日期相关_ASP基础

JavaScript is loosely typed. Database files are not. If you put text into a Boolean database column or a Boolean value into a date/time column, then you will get an error. For the most part this is not a problem, except for date/time. It does not cor

javascript asp教程More About Recordsets_ASP基础

Below we will attempt to access data from a database without knowing the column names. Clearly the best way to utilize data in your database is to keep track of your schema. Schema is the layout of data in your database. The concept is well beyond th

javascript asp教程Recordset记录_ASP基础

Recordset is another created/instanciated Object. It is a collection of data taken from a database. Recordset has 26 properties, 25 methods, 11 events, and two (2) collections. The vast majority of Recordset is beyond the scope of this web site. Quic

javascript asp教程创建数据库连接_ASP基础

While this section is devoted to ASP database utilization, it very important to remember that this web site is not intended to be a thorough ASP resource. Remember, the focus of this site is strictly limited to how to use JavaScript as your primary s

javascript asp教程第五课--合二为一_ASP基础

两条防线,一个函数: 试问你如何能保证客户端和服务器端具有相同的功能?表单域的验证闪现在我们眼前.别人把你的html复制到另外一个脚本,然后改变客户端的表单域验证--这并不是一件难事.摆在眼前的解决方法是将表单域的验证放置在服务器端.但那又意味着因为使用者的一个小错误,都要给服务器端要返回一串的错误信息.那么,我们何不同时拥有二者呢?不仅仅如此,我们还可以在客户端和服务器端使用同一个javascript函数来保证二者的完全一致性. 看看下面这一小段,请特别注意一下checkMyZip()函数.

javascript asp教程第六课-- response方法_ASP基础

response 对象:reponse是asp中六个对象之一.它代表了服务器端对浏览器的回应.response有8种方法,9种属性和一个集.在这一课,我们就重点讲述方法.方法:在javascript中,asp方法使用括号.请注意依赖response.buffer的两个方法,我们将在下一课讲到他们.同样应该注意到addheader()和redirect(),因为他们必须优先于write()执行.所有的方法都在上面描述和演示了.下面我将详细讲述每一个方法.我将花点额外的时间来讲述我们用的最多的两个方

javascript asp教程第六课-- response方法

response 对象: reponse是asp中六个对象之一.它代表了服务器端对浏览器的回应.response有8种方法,9种属性和一个集.在这一课,我们就重点讲述方法. 方法: 在javascript中,asp方法使用括号.请注意依赖response.buffer的两个方法,我们将在下一课讲到他们.同样应该注意到addheader()和redirect(),因为他们必须优先于write()执行. 所有的方法都在上面描述和演示了.下面我将详细讲述每一个方法.我将花点额外的时间来讲述我们用的最多