try catch throw用法

var x = prompt("Enter a number between 0 and 10:","") 
        
        try {
            if (x > 10) 
            {
                throw "Err1";
            }
            else if (x < 10) 
            {
                throw "Err2";
            }
        } catch(er) {
            if (er == "Err1") 
            {
                console.log("Error! The value is too high");
            }
            
            if (er == "Err2") 
            {
                console.log("Error! The value is too low");
            }
        }

 

posted @ 2012-06-20 15:28  穆乙  阅读(661)  评论(0编辑  收藏  举报