On this page

    M

    process.addUncaughtExceptionCaptureCallback

    History
    process.addUncaughtExceptionCaptureCallback(fn): void
    Stability: 1Experimental
    Attributes

    The process.addUncaughtExceptionCaptureCallback() function adds a callback that will be invoked when an uncaught exception occurs, receiving the exception value as its first argument.

    Unlike process.setUncaughtExceptionCaptureCallback(), this function allows multiple callbacks to be registered and does not conflict with the domain module. Callbacks are called in reverse order of registration (most recent first). If a callback returns true, subsequent callbacks and the default uncaught exception handling are skipped.

    import process from 'node:process';
    
    process.addUncaughtExceptionCaptureCallback((err) => {
      console.error('Caught exception:', err.message);
      return true; // Indicates exception was handled
    });
    process.addUncaughtExceptionCaptureCallback((err) => {
      console.error('Caught exception:', err.message);
      return true; // Indicates exception was handled
    });