- 热门文章:
- · 加快 DHTML 的一组技巧(Copy from Microsoft)
- · 一个不太让人讨厌的自动弹出窗口:)
- · 一个把数字转英文的实用程序
- · rollarea.js及其用法示例
- · 下拉框连动的小例子(.htm版)
- · 判断访问者的浏览器是否支持javascript和Cookies
- · 在Windows桌面上使用WSH接收邮件 (转)
- · HTML4.0的 Access Key
- · 绝对是好东西 (select1 <==> select2):
- · 一个类似vbscript的round函数的javascript函数
- · 用javascript检查yyyy-mm-dd格式的正确源码。
- · HEAD元素使用集锦 (转)
上一篇:VBSctipt 5.0中的新特性 >>
Jscript 5.0中的新特性
Jscript 5.0中的新特性
Jscript 5.0唯一的改变是引入了错误处理。
Java风格的try和catch结构在Jscript 5.0中得到了支持。例如:
Function GetSomeKindOfIndexThingy() {
Try {
// If an exception occurs during the execution of this
// block of code, processing of this entire block will
// be aborted and will resume with the first statement in its
// associated catch block.
Var objSomething = Server.CreateObject (“SomeComponent”);
Var intIndex = objSomething.getSomeIndex();
Return intIndex;
}
catch (exception) {
// This code will execute when *any* exception occurs during the
// execution of this function
alert (‘Oh dear, the object didn’t expect you to do that’);
}
}
内建的Jscript Error对象有3个属性,它们定义了上次的运行期错误。可在catch块中使用它们获得有关错误的更多信息。
Alert (Error.number); // Gives the numeric value of the error number
// And the result with 0xFFFF to get a ‘normal’ error number in ASP
Alert (error.description); // Gives an error desciption as a string
假如你想招抛出自己的错误,可用一个定制的异常对象引发一个错误(或异常)。然而,由于没有内建的异常对象,必须自己定义一个结构:
// Define our own Exception object
function MyException (intNumber, strDescripton, strInfo) {
this.Number = intNumber; // Set the Number property
this.Description = strDescription; // Set the Description property
this.CustomInfo = strInfo; // Set some ‘information’ property
}
这样的对象可用来在页面中引发定制的异常。这通过使用throw关键字,然后检查catch块中的异常类型来实现:
function GetSomeKindOfIndexThingy() {
try {
Var objSomething = Server.CreateObject (“SomeComponent”);
Var intIndex = objSomething.getSomeIndex();
If (intIndex == 0) {
// Create a new MyException object
theException = new MyException (0x6F1, “Zero index not permitted”,
“Index_Err”);
throw theException;
}
catch (objException) {
if (objException instanceof MyException) {
// This is one of our custom exption objects
if (objException.Category == “Index_Err”) {
alert (‘Index Error: ‘ + objException.Description);
else
alert (‘Undefined custom error: ‘ + objException.Description);
}
else
// Not “our” exception, so display it and raise to next higher routine
alert (Error.Description + ‘ (‘ + Error.Number + ‘)’);
throw exception;
}
}
}
相关文章:
- · 脚本控制Frame (转)
- · vbscript错误代码及对应解释大全
- · jscript错误代码及相应解释大全
- · 打开最大化窗口的一点经验
- · 无偿贡献,进入页面后自动刷新一次
- · 庆祝 Joy ASP 上贴数超过800页!!! 送给大家一个小礼物 ^_^
- · 自己动手,结合javascript和dhtml做一个ubb编辑器(附例子代码)
- · 选择最快的镜像站点
- · 一段有趣并且实用的程序--利用javascript和dhtml实现两个列表框中内容的移动。(代码见内,把它存为一个...
- · 动态菜单的另一种实现(一) category.js
- · 动态数组的另一种实现(二) 界面
- · 实际使用“DXML”:在站点上实现 DHTML 菜单和目录(co.)
- · 以前收集的一些资料---JS中处理日期的一些函数和方法
- · 以前搜集的一些资料---html中的特殊字符(2)
- · 以前搜集的一些资料---html中的特殊字符(1)
- · 在浏览器里实现类似VB Form的界面控制
- · CSS2参考之一(转贴)
- · CSS2参考之二(转贴)
- · CSS2参考之三(转贴)
- · CSS2参考之四(转贴)
- · CSS2参考之五(转贴)
- · CSS2参考之六(转贴)
- · CSS2参考之七(转贴)
- · CSS2参考之八(转贴)
- · CSS2参考之九(转贴)
- · CSS2参考之十一(转贴)<完>
- · CSS2参考之十(转贴)
- · 李由的奉献(一)----Windows Scripting Host 对象参考
- · CSS2参考之零(转贴)
- · 李由的奉献(二)----Wscript 对象
- · 李由的奉献(三)----WshArguments 对象
- · 李由的奉献(四)----WshShell 对象
- · 李由的奉献(五)----WshNetwork 对象
- · 李由的奉献(六)----WshShortcut 对象
- · 李由的奉献(七)----WshUrlShortcut 对象
- · 李由的奉献(八)----WshCollection 对象
- · 李由的奉献(九)----WshEnvironment 对象
- · 李由的奉献(十)----WshSpecialFolders 对象
