joyent/node — pull request #6011 by trevnorris (2013-08-07 18:56:10+00:00)
Title: WIP: implement domain-like hooks for userland

This is still dependent on a couple other patches I'm working on (e.g. better C++/JS state sharing) but figured it gets the idea across. Here's an uber simplified example:
```javascript
process.addAsyncListener(function(cb, obj) {
return function asyncWrapper() {
try {
cb();
} catch(e) {
console.error('CAUGHT', e.stack);
}
};
});

process.nextTick(function() {
throw new Error('DIE DIE DIE');
});

process.nextTick(function() {
console.log('march on');
});

// output:
// CAUGHT Error: DIE DIE DIE
// march on
```