1'use strict'; 2require('../common'); 3 4if (process.argv[2] === 'child') { 5 process.on('uncaughtException', (err) => { 6 err.rethrow = true; 7 throw err; 8 }); 9 10 function throwException() { 11 throw new Error('boom'); 12 } 13 14 throwException(); 15} else { 16 const assert = require('assert'); 17 const { spawnSync } = require('child_process'); 18 const result = spawnSync(process.execPath, [__filename, 'child']); 19 20 assert.strictEqual(result.status, 7); 21 assert.strictEqual(result.signal, null); 22 assert.strictEqual(result.stdout.toString().trim(), ''); 23 // Verify that the error was thrown and that the stack was preserved. 24 const stderr = result.stderr.toString(); 25 assert(/Error: boom/.test(stderr)); 26 assert(/at throwException/.test(stderr)); 27 assert(/rethrow: true/.test(stderr)); 28} 29