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
-
The constructor doesn't receive any parameters so there's nothing to check.
-
Should the
setItem
setter check for anull
? No.- The code would already throw a
NullPointerException
. So, throwing anIllegalArgumentException
would be redundant.
- The code would already throw a
Upon inspecting the Store
class, applying further quality control isn't necessary.
Feedback Summary
4.7
43 students
5
91%
4
2%
3
0%
2
0%
1
7%
Written Reviews
There are no written reviews yet.