Java Java Objects Delivering the MVP Validating and Normalizing User Input

Is everything in the "try" block being run?

Is everything in the "try" block always being run? Or does it stop and go to the catch block as soon as an IllegalArgumentException is picked up? For example below, could you confirm that the code would not run the "isValidLetter = true" line if the "isHit = game.applyGuess(guess);" produced the IllegalArgumentException error?

  try {
    isHit = game.applyGuess(guess);
    isValidLetter = true;
  } catch(IllegalArgumentException iae) {
  System.out.printf("%s Please try again..%n",
                    iae.getMessage());
  }

1 Answer

saykin
saykin
9,820 Points

As soon as a Exception is thrown by line of code in the try/catch block, it skips the rest and jumps to the catch block.