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
Pranjal Agnihotri
4,187 PointsException Handling in Java
Why do we use "new" keyword while throwing exception. Like for e.g. throw new IllegalArgumentException. Why did we use new there.
1 Answer

Craig Dennis
Treehouse TeacherHi Pranjal Agnihotri !
Because it is a class, so you are creating a new instance of the IllegalArgumentException
class.
If you are really interested you can take a look at the source code since everything is open.
Does that make sense?
Pranjal Agnihotri
4,187 PointsPranjal Agnihotri
4,187 PointsThank you sir , Now I understood that's why you were using getMessage() which is a method of that IllegalArgumentException class.
Craig Dennis
Treehouse TeacherCraig Dennis
Treehouse Teacher