當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Node.js process.hasUncaughtExceptionCaptureCallback()用法及代碼示例


process.hasUncaughtExceptionCaptureCallback()方法是流程模塊的內置應用程序編程接口,用於獲取是否已使用process.setUncaughtExceptionCaptureCallback()方法設置回調。

用法:

process.hasUncaughtExceptionCaptureCallback()

參數:此方法不接受任何參數。


返回值:它返回一個布爾值,該布爾值指定是否已使用process.setUncaughtExceptionCaptureCallback()設置了回調。

以下示例說明了Node.js中process.hasUncaughtExceptionCaptureCallback()方法的使用:

範例1:

// Node.js program to demonstrate the    
// process.hasUncaughtExceptionCaptureCallback() Method 
  
// Include process module 
const process = require('process'); 
  
console.log(process.hasUncaughtExceptionCaptureCallback()); 
  
// Printing whether a callack is set or not 
if(process.hasUncaughtExceptionCaptureCallback()) { 
    console.log("A callback has been set using "
    + "process.setUncaughtExceptionCaptureCallback() method"); 
}else{ 
        console.log("No callback has been set using "
        + "process.setUncaughtExceptionCaptureCallback() method"); 
}

輸出:

false
No callback has been set using process.setUncaughtExceptionCaptureCallback() method

範例2:

// Node.js program to demonstrate the    
// process.hasUncaughtExceptionCaptureCallback() Method 
  
// Include process module 
const process = require('process'); 
   
function to_be_called(ex){ 
    console.log(ex); 
} 
  
// Setting callback  
process.setUncaughtExceptionCaptureCallback(to_be_called); 
   
console.log(process.hasUncaughtExceptionCaptureCallback()); 
  
// Printing whether a callack is set or not 
if(process.hasUncaughtExceptionCaptureCallback()){ 
    console.log("A callback has been set using "
    + "process.setUncaughtExceptionCaptureCallback() method"); 
}else{ 
    console.log("No callback has been set using "
    + "process.setUncaughtExceptionCaptureCallback() method"); 
}

輸出:

true
A callback has been set using process.setUncaughtExceptionCaptureCallback() method

注意:上麵的程序將通過使用node filename.js命令。

參考: https://nodejs.org/api/process.html#process_process_hasuncaughtexceptioncapturecallback



相關用法


注:本文由純淨天空篩選整理自anwesha0107大神的英文原創作品 Node.js | process.hasUncaughtExceptionCaptureCallback() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。