mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
9dcc9b6a6b
This adds a flag to define the default behavior for unhandled rejections. Three modes exist: `none`, `warn` and `strict`. The first is going to silence all unhandled rejection warnings. The second behaves identical to the current default with the excetion that no deprecation warning will be printed and the last is going to throw an error for each unhandled rejection, just as regular exceptions do. It is possible to intercept those with the `uncaughtException` hook as with all other exceptions as well. This PR has no influence on the existing `unhandledRejection` hook. If that is used, it will continue to function as before. PR-URL: https://github.com/nodejs/node/pull/26599 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Matheus Marchini <mat@mmarchini.me> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
24 lines
591 B
JavaScript
24 lines
591 B
JavaScript
// Flags: --unhandled-rejections=none
|
|
'use strict';
|
|
|
|
const common = require('../common');
|
|
|
|
common.disableCrashOnUnhandledRejection();
|
|
|
|
// Verify that ignoring unhandled rejection works fine and that no warning is
|
|
// logged.
|
|
|
|
new Promise(() => {
|
|
throw new Error('One');
|
|
});
|
|
|
|
Promise.reject('test');
|
|
|
|
process.on('warning', common.mustNotCall('warning'));
|
|
process.on('uncaughtException', common.mustNotCall('uncaughtException'));
|
|
process.on('rejectionHandled', common.mustNotCall('rejectionHandled'));
|
|
|
|
process.on('unhandledRejection', common.mustCall(2));
|
|
|
|
setTimeout(common.mustCall(), 2);
|