当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。