Node.js process.report.reportOnUncaughtException 属性
process对象是一个全局对象,它提供有关当前 Node.js 进程的信息并对其进行控制。作为一个全局变量,它始终可供 Node.js 应用程序使用,而无需使用 require()。它也可以使用 require() 显式访问,如下所示:
const process = require('process');
如果process.report.reportOnUncaughtException为真,则会针对未捕获的异常生成诊断报告。
句法:
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.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: 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