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 (Retired) Delivering the MVP Validation

Shariq Shaikh
Shariq Shaikh
13,945 Points

So what part of the code that we just wrote is the actual test?

It seems that the try catch blocks that we wrote are implemented to prevent the user from passing in an illegal argument rather than testing the functionality of the code. Can someone clarify what specifically was the test?

1 Answer

Allan Clark
Allan Clark
10,810 Points

A try-catch block is used when an exception is possible and we do not want to allow the program to crash if the exception occurs. In this example the validateGuess() method may throw an exception, if the character received is not a letter or if the letter received has already been guessed. The try-catch block, tries to validate the guess and if it catches the exception it runs what is in the catch block.

Hope this helps