0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/test/mjsunit/test-exception-handler.js
Felix Geisendörfer 2b252acea4 Implement process "uncaughtException" event
This event can be used to overwrite the default exception mechanism which
reports the exception and kills the node process.

See google group post:
http://groups.google.com/group/nodejs/browse_thread/thread/9721dc3a2638446f
2009-11-14 23:46:37 +01:00

26 lines
570 B
JavaScript

process.mixin(require("./common"));
var MESSAGE = 'catch me if you can';
var caughtException = false;
process.addListener('uncaughtException', function (e) {
puts("uncaught exception! 1");
assertEquals(MESSAGE, e.message);
caughtException = true;
});
process.addListener('uncaughtException', function (e) {
puts("uncaught exception! 2");
assertEquals(MESSAGE, e.message);
caughtException = true;
});
setTimeout(function() {
throw new Error(MESSAGE);
}, 10);
process.addListener("exit", function () {
puts("exit");
assertTrue(caughtException);
});