2013-10-28 86 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"); 
}