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


Node.js process.report.reportOnUncaughtException用法及代碼示例

流程對象是一個全局對象,提供有關當前Node.js流程的信息並對其進行控製。全局而言,它始終可用於Node.js應用程序,而無需使用require()。也可以使用require()對其進行顯式訪問,如下所示:

const process = require('process');

如果process.report.reportOnUncaughtException為true,則會針對未捕獲的異常生成診斷報告。

用法:

process.report.reportOnUncaughtException

參數:此屬性不接受任何參數。

返回值:此屬性返回一個布爾值。



以下示例說明了Node.js中process.report.reportOnUncaughtException屬性的用法:

範例1:

index.js


// Node.js program to demonstrate the  
// process.report.reportOnUncaughtException Property  
       
// Include process module  
const process = require('process');  
      
// Printing process.report.reportOnUncaughtException property value  
console.log(`Report on exception: 
   ${process.report.reportOnUncaughtException}`);

使用以下命令運行index.js文件:

node index.js

輸出:

Report on exception:false

範例2:

index.js


// Node.js program to demonstrate the  
// process.report.reportOnUncaughtException Property  
       
// Include process module  
const process = require('process');  
  
process.report.reportOnUncaughtException = true;
  
// Printing process.report.reportOnUncaughtException property value  
console.log(`Report on exception: 
   ${process.report.reportOnUncaughtException}`);

使用以下命令運行index.js文件:

node index.js

輸出:

Report on exception:true

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

相關用法


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