0
    for (var i = 0, len = IDs.length; i < len; i++) {

    entry = IDs[i];
    isAnyFailure = false;

    try{
    var id = db.getSiblingDB("door").jhi_user.findOne({"_id" : entry});
    } catch (err){

     failedIDs.push(entry);
     failedCount++;
     isAnyFailure = true;
    }

...
}

if it catches any error, it will continue to code or it will go to next iteration?

2
  • 1
    why don't you log your code, or step through in a debugger and see? Commented Apr 6, 2017 at 6:48
  • 1
    It should continue with the next iteration.. Commented Apr 6, 2017 at 6:49

1 Answer 1

2

The loop continues in try and catch:

    for (var i = 0; i < 10; i++)
    {
      try
      {
        if(i == 6)
        {
          document.getElementById('noid').html("x"); //this will cause an exception as no such ID exists
        }
        console.log("In try Iteration :: "+i);
      }
      catch (err)
      {
        console.log("In catch Iteration :: "+i);
      }
    }

The whole concept of try and catch is to continue the execution if an exception occurs rather than abruptly stopping the program / script.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.