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

Why use the entire Try/Catch/Throw fiasco instead of an if?

I dont understand, instead of turning heads regarding this, why not just use: public boolean applyGuess(char letter) { if(hits.indexOf(letter)!=-1 || misses.indexOf(letter)!=-1) { System.out.println("You've already tried this guess."); return false; } .....//rest of method

1 Answer

Maybe this is a simple case and you can handle it with just on simple if else but look at this https://docs.oracle.com/javase/tutorial/essential/exceptions/advantages.html