I am throwing an exception in the context of closure and can't catch it. Here is a trivial example.
try{
setTimeout(function(){ throw Error() },100)
}
catch(error)
{
console.log("YES",error);
}
It never makes it to the catch clause and causes my node process to terminate. Same issue here:
try{
setTimeout(function(){undefinedMethod() },100)
}
catch(error)
{
console.log("YES",error);
}
My real example is closer to this:
try{
var ctx={setTimeout:setTimeout};
require('vm').runInNewContext("setTimeout(function(){undefinedMethod() },100)",ctx)
}
catch(error)
{
console.log(error);
}
I need the try/catch as safety measure. Currently this behaviour causes my node process to terminate. How can I catch the exception?