Last active
October 12, 2015 18:04
-
-
Save tjmehta/9c4d4266b93c71465ea0 to your computer and use it in GitHub Desktop.
Unexpected domain error handling
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Domain = require('domain') | |
var d1 = Domain.create(); | |
var emitter; | |
d1.on('error', handleCreateErr) | |
d1.run(function () { | |
emitter = createEmitter() | |
}) | |
var d2 = Domain.create(); | |
d2.on('error', handleEmitterErr) | |
d2.run(function () { | |
emitter.on('foo', function () { | |
throw new Error('something bad happenned'); | |
}) | |
emitter.emit('foo') | |
}) | |
function handleCreateErr (err) { | |
console.error('error creating event emitter', err.stack); | |
} | |
function handleEmitterErr (err) { | |
console.error('error using event emitter', err.stack); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An error occurs above when using the event emitter, but ends up triggering an
error
event ford1
.This leads to unexpected behavior, and print the wrong error message (error creating event emitter).