I'm using async waterfall. When one of my functions calls callback(err), my custom async callback is called. Inside of there I throw an error, hoping it will be caught in the try block around async, but that's not happening.
try {
async.waterfall([function1, function2], myAsyncCallback);
}
catch(err) {
console.log("THIS CODE IS NEVER EXECUTED.");
}
var function1 = function() {
...
//some error occurs:
callback(new Error(errMsg), errMsg);
...
}
var function2 = function() {
...
}
function myAsyncCallback(err, result) {
console.log("This code gets executed.");
if (err) {
console.log("This code gets executed too.");
throw new Error("I want this error caught at the top around the catch around async.waterfall()");
}
}
myAsyncCallbackinside of yourfunction1, so this is not really sensible code. Can you please reduce this to a minimal reproducible example that people can copy-paste to a file and run in node to see the same thing you see, instead of posting code that is guaranteed to not show your problem because it can't run?