Java Bootcamp – Workbooks and Challenges
)}

Shopping Cart – Part 7

Goal: Quality control the Store class.

Unchecked exceptions

An unchecked exception crashes the app as a result of badly written code.

You should throw an:

  • IllegalArgumentException when the caller passes faulty arguments into a method/constructor.

  • IllegalStateException when an object calls its method at a "bad time" (object not in a legal state).

Throwing an unchecked exception forces the caller to improve their code.

Task 1 – Inspecting the Store class


  1. The constructor doesn't receive any parameters so there's nothing to check.

  2. Should the setItem setter check for a null? No.

    • The code would already throw a NullPointerException. So, throwing an IllegalArgumentException would be redundant.

Upon inspecting the Store class, applying further quality control isn't necessary.


Feedback Summary
4.8
39 students
5

92%
4

3%
3

0%
2

0%
1

5%
Written Reviews
There are no written reviews yet.