2013-10-28 46 views
-2

如何在node.js中做一个非常基本的功能测试?这里的逻辑:node.js中的基本功能测试

try { 
    function a()... 
    console.log("i am using function a"); 
} catch(err){ 
    console.log(err) 
} or { 
    function b()... 
    console.log("i am using function b"); 
} 

如果第一个函数失败,打印出ERR日志,并继续使用第二功能,如果不使用第一个函数。

回答

1

如果您的try块引发异常,则只会触击catch块。实际上,catch区块是or

try { 
    a(); 
    console.log("i am using function a"); 
} catch (err) { 
    console.log(err); 
    b(); 
    console.log("i am using function b"); 
}