Skip to content

Instantly share code, notes, and snippets.

@adoyle-h
Created June 26, 2016 14:30
Show Gist options
  • Save adoyle-h/8675c0335b7436af2d4562343e51b55e to your computer and use it in GitHub Desktop.
Save adoyle-h/8675c0335b7436af2d4562343e51b55e to your computer and use it in GitHub Desktop.
var vm = require('vm');
function printError(e) {
// console.log(e instanceof Error, e, e.stack);
console.log(e instanceof Error);
}
console.log('====== Example 1 ======');
try {
vm.runInNewContext('throw new Error("nooooo")');
} catch(e) {
printError(e);
}
console.log('====== Example 2 ======');
try {
vm.runInThisContext('throw new Error("nooooo")');
} catch(e) {
printError(e);
}
console.log('====== Example 3 ======');
try {
vm.runInNewContext('throw new Error("nooooo")', {Error: Error}, {displayErrors: false});
} catch(e) {
printError(e);
}
console.log('====== Example 4 ======');
try {
var sandbox = {Error: Error};
vm.createContext(sandbox);
vm.runInContext('throw new Error("nooooo")', sandbox, {displayErrors: false});
} catch(e) {
printError(e);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment