Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Why domains does not catch below exception?

Why domains does not catch below exception?

Problem

Why domain does not handle below error?

var globalDomain = domain.createDomain();

globalDomain.run( function() {
    // Why below exception does not get handled by globalDomain?
    throw "some error"; 
});

globalDomain.on('error', function(msg) {
    console.log("In global error event:" + msg);
});

Again, It works perfectly well with below code,

var globalDomain = domain.createDomain();

globalDomain.run( function() {
    setTimeout(function(){
        throw "some error from timeout";
    },0);
});

globalDomain.on('error', function(msg) {
    console.log("In global error event:" + msg);
});
Problem courtesy of: SunnyShah

Solution

var globalDomain = domain.createDomain();

globalDomain.on('error', function(msg) {
    console.log("In global error event:" + msg);
});

globalDomain.run( function() {
    //  exception gets handled by globalDomain !!
    throw "some error"; 
});
Solution courtesy of: Ashish

Discussion

View additional discussion.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

Why domains does not catch below exception?

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×