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 trialAditya Sheode
1,291 PointsWhy getMessage?
I did not Understand as to why he used get message on iae. Does anyone else have this question?
3 Answers
Steve Hunter
57,712 PointsHiya,
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.
Steve Hunter
57,712 PointsHi 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
1,291 PointsThanks man! Steve I just had two more questions and I am a lil hazy regarding constructors.. is there supposed to be only 1 constructor?