关于 try catch

<script>
        function createXMLDOM(){
    var arrSignatures = ["MSXML2.DOMDocument.5.0","MSXML2.DOMDocument.4.0",
                                    "MSXML2.DOMDocument.3.0","MSXML2.DOMDocument",
                                    "Microsoft.XmlDom"];
     for(var i=0;i<arrSignatures.length;i++)
     {
           try{
                    var oXmlDom = new ActiveXObject(arrSignatures[i]);
                    return oXmlDom;
           }catch(oError){
                    //ignore
           }
     }
    
     throw new Error("not");
    
}

var oXmlDom = createXMLDOM();
</script>

 

new一句中有的可以创建有的不能创建,这里的目的是抓取可以创建的那个并返回,此时可以放在try里,而catch不管,在左后的时候再抛出异常,说明for循环里全部都抛出了异常。

你可能感兴趣的:(关于 try catch)