Skip to content

Instantly share code, notes, and snippets.

@sudsy
Forked from owenallenaz/caught.js
Last active December 26, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sudsy/7162271 to your computer and use it in GitHub Desktop.
Save sudsy/7162271 to your computer and use it in GitHub Desktop.
Showing that node.js domains do catch synchronous errors (caught.js). Showing that try catch can interfere with nodejs domains (notcaught.js).
var domain = require("domain");
var d = domain.create();
d.on("error", function() {
console.log("domain caught");
});
d.run(function() {
throw new Error("foo");
});
// result: domain caught
var domain = require("domain");
var d = domain.create();
d.on("error", function() {
console.log("domain caught");
});
try {
d.run(function() {
throw new Error("foo");
});
} catch (err) {
console.log("try/catch caught");
}
// result: try/catch caught
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment