GeezerVison is showing github.com — src: allow fatal exceptions to be enhanced · jaku/node@36fdf1a
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/node_errors.cc +3-2Lines changed: 3 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -448,10 +448,11 @@ TryCatchScope::~TryCatchScope() { |
448 | 448 | HandleScope scope(env_->isolate()); |
449 | 449 | Local<v8::Value> exception = Exception(); |
450 | 450 | Local<v8::Message> message = Message(); |
| 451 | + EnhanceFatalException enhance = CanContinue() ? |
| 452 | + EnhanceFatalException::kEnhance : EnhanceFatalException::kDontEnhance; |
451 | 453 | if (message.IsEmpty()) |
452 | 454 | message = Exception::CreateMessage(env_->isolate(), exception); |
453 | | - ReportFatalException( |
454 | | - env_, exception, message, EnhanceFatalException::kDontEnhance); |
| 455 | + ReportFatalException(env_, exception, message, enhance); |
455 | 456 | env_->Exit(7); |
456 | 457 | } |
457 | 458 | } |
|
Collapse file
Copy file name to clipboard +28Lines changed: 28 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 1 | +'use strict'; |
| 2 | +require('../common'); |
| 3 | + |
| 4 | +if (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 | +} |