summaryrefslogtreecommitdiff
path: root/test/simple/test-exception-handler.js
blob: 6c4923e8e5d77aab3e5ae0a25690260e75a919b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
var common = require('../common');
var assert = require('assert');

var MESSAGE = 'catch me if you can';
var caughtException = false;

process.addListener('uncaughtException', function(e) {
  console.log('uncaught exception! 1');
  assert.equal(MESSAGE, e.message);
  caughtException = true;
});

process.addListener('uncaughtException', function(e) {
  console.log('uncaught exception! 2');
  assert.equal(MESSAGE, e.message);
  caughtException = true;
});

setTimeout(function() {
  throw new Error(MESSAGE);
}, 10);

process.addListener('exit', function() {
  console.log('exit');
  assert.equal(true, caughtException);
});