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

How to choose an exception

Mr.Craig here choose to throw the IllegelArgumentException. How many exceptions are there and how to choose one? please explain!

1 Answer

Brendon Butler
Brendon Butler
4,254 Points

There are tons of exceptions. You can even create your own. Probably the most common one you'll run into would be the NullPointerException.

NullPointerException: Thrown when an application attempts to use an object reference that has a null value. For example, if you were to run this code in an IDE, you would get a "NullPointerException.":

String helloWorld = null;

helloWorld.toUpperCase();

You're not going to use all the exceptions available to you. Probably less than 5% of them. I'll leave some helpful links that should help you understand them better.

Java SE 8 Exceptions - JavaDoc | Lesson on Exceptions