Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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,835 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.