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) Harnessing the Power of Objects Exceptions

the "if" statement

I was confused in the "load(int pezAmount)" method. Is the "mPezAmount = newAmount" the "else" in the if statement?

1 Answer

1  if (newAmount > MAX_PEZ) {
2      throw new . . . ;
3  }
4  mPezCount = new Amount;
5  . . .

Technically line 4 is not the else... for the if... statement, because there is no else.... But from the practical point of view, yes, it could be considered such. If newAmount is greater than MAX_PEZ the program throws an exception and stops. If it's not, then the flow of control goes from line 1 to line 4. The code could be rewritten to put what follows in an else { . . . } statement, but for many that just makes it more complicated.