• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

Jscript 5.0中的新特性

发布: 2007-6-30 18:56 | 作者: admin | 来源: | 查看: 13次 | 进入软件测试论坛讨论

领测软件测试网  
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;
                     }
              }
       }

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备10010545号-5
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网