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 trialAndre Kucharzyk
4,479 Pointswhat is "iae" in catch (IllegalArgumentException iae)?
what is "iae" in catch (IllegalArgumentException iae)?
5 Answers
Steve Hunter
57,712 PointsHi Andre,
You are creating an instance IllegalArgumentException
and calling it iae
, passing that into the catch
process.
Make sense?
Steve.
nfs
35,526 PointsDoes it mean that it could be called anything? That name need not necessarily be iae, does it? Could I easily call it cat or dog or even Yoda? If that's the case, then the only reason for naming it iae would be to make it conventional, am I right?
Steve Hunter
57,712 PointsYes, you are right. It can be called anything.
Steve.
nfs
35,526 PointsThank you, Steve Hunter.
Steve Hunter
57,712 PointsNo problem!
Steve Hunter
57,712 PointsJun Dong You had a query that you deleted. Can I help?
Steve Hunter
57,712 PointsNo you didn't delete it - I just saw it further up. Apologies!!
Jun Dong
4,754 PointsThanks but I have another question, what if you created multiple IllegalArgumentExceptions, and then you named them afterwards, how will it know which one you're talking about?
Steve Hunter
57,712 PointsHi again!
You can't label an exception before it has been created. So, you are writing code here to try
your code and if it throws an IllegalArgumentException
you are using catch
to manage that specific error/exception. Each IllegalArgumentException
that is thrown will be managed by your catch
block.
With this construction of code, each exception will be managed in exactly the same way - you cannot manage different IAEs with this type of catch
.
Make sense?
Steve.
Jun Dong
4,754 PointsSo it tests every IllegalArgumentException you created?
Steve Hunter
57,712 PointsThe code is exception-ready. If an illegal argument exception is thrown, the code can handle it. We're not creating the exception deliberately but are handling one should it appear.
Andre Kucharzyk
4,479 PointsAndre Kucharzyk
4,479 PointsIt does. Thanks for the help!
Jun Dong
4,754 PointsJun Dong
4,754 PointsWait so you are creating the IllegalArgumentException in PezDispenser.java, and naming it in Example.java? And what does getMessage() do?
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsJun Dong Yes. You are correct. In
PezDispenser.java
you create the functionality to make an `IllegalArgumentExeption
. InExample.java
you manage an instance of that exception within your try/catch block.So, you don't create an instance of an
IllegalArgumentException
until you hit the `catch
but you have the mechanics to deal with that instance when it is required.That's quite esoteric - ask me more questions and I'll fill in the blanks.
Steve.