Yes, he will be caught: but only when making a callback. That is, if an riskyFuncexception is thrown, it will not fall into your example until the callback is completed in one second.
You've probably heard before that when using asynchronous methods, you should be careful with exceptions, and ordinary people do this:
try {
setInterval(function() {
riskyFunc();
}, 1000);
} catch(e) {
console.error(e);
}
, riskyFunc . , , setInterval; , setInterval , try/catch. : .
riskyFunc , . :
function riskyFunc() {
asyncFn(function(){
throw new Error('argh');
}
}
try/catch setInterval. :
function riskyFunc() {
asyncFn(function() {
try {
} catch(e) {
console.error(e);
}
}
}
, " ", promises - /. , "" , :
function riskyFunc(done) {
asyncFn(function() {
try {
done(null, 'all done!');
} catch(e) {
done(e);
}
}
}
setTimeout :
setTimeout(function() {
try {
riskyFunc(function(err, msg) {
if(err) return console.error(err);
console.log(msg);
});
} catch(e) {
console.error(e);
}
}