Question 4
Back to Exercise
A constructor receives arguments that would make the object invalid. What is the best response?
- A Store them anyway and fix them later
- B Throw an exception so that no invalid object is ever created Correct
- C Print a warning and continue
- D Set all members to zero silently
Correct Answer: Option B
If the constructor throws, the object never exists, so every existing object satisfies the invariant.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!