Java Bootcamp – Workbooks and Challenges
)}

Contacts – Part 7

A "bulletproof" application is free of bugs and doesn't fail/crash no matter what. The key is to:

  1. catch checked exceptions (outside the application's control).

  2. fix unchecked exceptions (resulting from badly written code).

There aren't any checked exceptions. So, your primary focus is to fix unchecked exceptions.

Task 1 – IllegalArgumentException


Thrown to indicate that a method has been passed an illegal or inappropriate argument.

If the user tries to enter a blank name or phoneNumber, the Contact constructor will throw an IllegalArgumentException.

Your code needs to anticipate such a scenario and println: "\nThe input you provided is not valid. Registration failed.");

Task 2 – IllegalArgumentException


Thrown to indicate that a method has been passed an illegal or inappropriate argument.

If the user tries to enter a number less than 5 characters, the Contact constructor will throw an IllegalArgumentException.

In the same if statement as task 1, check if the phone number has less than 5 characters.

Your code is now bulletproof!

No matter what the user throws at you, the application is free of bugs and will never crash. It can process any input and respond gracefully.

Final Output

Feedback Summary
4.8
38 students
5

92%
4

3%
3

0%
2

0%
1

5%
Written Reviews
There are no written reviews yet.