Skip to content

Instantly share code, notes, and snippets.

@CrabDude
Created March 27, 2012 19:26
Show Gist options
  • Save CrabDude/2219490 to your computer and use it in GitHub Desktop.
Save CrabDude/2219490 to your computer and use it in GitHub Desktop.
Trycatch EventEmitter Fail
var util = require("util"),
events = require("events"),
trycatch = require("trycatch");
function doit(that) {
trycatch(function() {
// Comment out this line and assign below, and trycatch works
if (!f) f = new foo
f.bar()
}, function(err) {
console.log(that)
console.log(err.stack)
})
}
function foo() {
this.on('bar', this.onBar)
}
util.inherits(foo, events.EventEmitter);
foo.prototype.bar = function() {
// EventEmitter breaks the catch function
this.emit('bar')
// This works though, even though it appears to be the same?
// this.onBar()
}
foo.prototype.onBar = function() {
throw new Error('wtf')
}
// Uncomment this assignment and assign above, and trycatch works
var f// = new foo
doit({a: 'b'})
doit({c: 'd'})
doit({e: 'f'})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment