Node.js process.hasUncaughtExceptionCaptureCallback() Method
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
// Node.js program to demonstrate the // process.hasUncaughtExceptionCaptureCallback() Method // Include process module const process = require( 'process' ); console.log(process.hasUncaughtExceptionCaptureCallback()); // Printing whether a callback 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" ); } |
Output:
false No callback has been set using process.setUncaughtExceptionCaptureCallback() method
Example 2:
Javascript
// 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 callback 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" ); } |
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
Contact Us