Created
March 27, 2012 19:26
-
-
Save CrabDude/2219490 to your computer and use it in GitHub Desktop.
Trycatch EventEmitter Fail
This file contains hidden or 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 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