漫漫技术人生路

C#

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

function g(f)
{
  //if(typeof(f) =='undefined')throw('You must enter an age');
  //错误是不能被捕获的因为这个位置处于构造函数阶段类的实例化阶段

  this.tt =f;
}


     g.prototype.h=function()
     {
        try
        {
           alert(this.tt);
          
           f=this.tt;
           if(typeof(f) =='undefined')throw('You must enter an age');

if(typeof(f) !='number') throw ('you must enter number');

if(f<0) throw ('age not allow less than 1');

if(f>100) throw ('you can\'t live longer than 100');

   return f;////after add return ,the content behind finally would not be executed any more but content in finally will still be excuted
        }
//        catch(ex)
//        {
//         // alert(ex.description)
//         alert(ex);
//        }
        catch(err)
        {  
          alert(err);
           return f;////after add return ,the content behind finally would not be executed any more but content in finally will still be excuted
         }
        finally
        {
          alert("must execute");
        }
       
        alert("can continue");
       
     }


var n =new g(-1);

n.h();//本例中在这个时候才会去捕捉错误


function pa(x)
{
  if(typeof(f) =='undefined')throw('You must enter an age');

if(typeof(f) !='number') throw ('you must enter number');

if(f<0) throw ('age not allow less than 1');

if(f>100) throw ('you can\'t live longer than 100');

var myAge = x;

alert(myAge);
}

var userInput =1000;
function f()
{
try{    pa((1000));}catch(err){    alert(err);}
}

//window.onload=f;

posted on 2006-12-11 17:03  javaca88  阅读(168)  评论(0)    收藏  举报