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

Aditya Sheode
Aditya Sheode
1,291 Points

Why getMessage?

I did not Understand as to why he used get message on iae. Does anyone else have this question?

3 Answers

Hiya,

The variable iae holds an instance of Illegal Argument Exception. That class has an instance method called getMessage() that retrieves the message associated with the error that generated the instance. In this case, you created an instance with:

throw new IllegalArgumentException("Too many PEZ!!");

So, this line gets called as you throw the error, the instance it creates gets stored in iae and you use the getMessage()` method on that instance to retrieve the message passed in with the constructor, "Too many PEZ!!!".

I hope that helps.

Steve.

Hi again,

Short answer; no.

A class can have no constructor (Java will provide a default one) or any number of constructors, as long as each one has a different signature. If each constructor requires different parameters there can be multiple constructors present.

Steve.

Aditya Sheode
Aditya Sheode
1,291 Points

Thanks man! Steve I just had two more questions and I am a lil hazy regarding constructors.. is there supposed to be only 1 constructor?