Node.js process.hasUncaughtExceptionCaptureCallback() Method
Last Updated :
12 Oct, 2021
The process.hasUncaughtExceptionCaptureCallback() method is an inbuilt application programming interface of the process module which is used to get whether a callback has been set using process.setUncaughtExceptionCaptureCallback() method.
Syntax:
process.hasUncaughtExceptionCaptureCallback()
Parameters: This method does not accept any parameters.
Return Value: It returns a boolean value specifying whether a callback has been set using process.setUncaughtExceptionCaptureCallback() or not.
Below examples illustrate the use of process.hasUncaughtExceptionCaptureCallback() method in Node.js:
Example 1:
Javascript
const process = require( 'process' );
console.log(process.hasUncaughtExceptionCaptureCallback());
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" );
}
|
Output:
false
No callback has been set using process.setUncaughtExceptionCaptureCallback() method
Example 2:
Javascript
const process = require( 'process' );
function to_be_called(ex){
console.log(ex);
}
process.setUncaughtExceptionCaptureCallback(to_be_called);
console.log(process.hasUncaughtExceptionCaptureCallback());
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" );
}
|
Output:
true
A callback has been set using process.setUncaughtExceptionCaptureCallback() method
Note: The above program will compile and run by using the node filename.js command.
Reference: https://nodejs.org/api/process.html#process_process_hasuncaughtexceptioncapturecallback
Share your thoughts in the comments
Please Login to comment...