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!
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
Aditya Puri1,080 Points
A little confused..
So I have some questions....
1) Is a type of exception, like the "IllegalArgumentException" a class? Is that why he wrote
throw new IllegalArgumentException?
2) Why did he write
IllegalArgumentException iae on the 31st line of Example.java.
Yes, exceptions in Java are classes.
When an exception is thrown an instance of the exception is created (just like you create instances of your own classes) the parameter list of the catch block is somewhat like the parameter list of a method, he is simply saying that the block of code requires an object of type IllegalArgumentException and that it should be set to the variable iae within the code block.
So when he calls iae.getMessage() on line 33 he is calling the getMessage method found on the IllegalArgumentException object that was created when the exception was thrown.
Exceptions are probably a bit confusing at this point but as you learn more about classes and inheritance and other such concepts, I'm sure you'll come to understand how they work. Heck you can even create your own exceptions once you learn a bit more about those things.