Created
June 26, 2016 14:30
-
-
Save adoyle-h/8675c0335b7436af2d4562343e51b55e to your computer and use it in GitHub Desktop.
This file contains 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 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