Question 9
Back to Exercise
The code below stops with an uncaught error. Which statement correctly describes the problem?
function charge(amount) {
try {
if (amount <= 0) throw new RangeError("amount must be positive");
return "charged";
} catch (err) {
console.log("logging failure…");
throw error;
}
}
charge(0);
- A RangeError: amount must be positive
- B ReferenceError: error is not defined – the catch variable is err, so the re-throw itself fails and hides the RangeError Correct
- C It returns "charged"
- D SyntaxError
Correct Answer: Option B
Write throw err;. The ReferenceError replaces the real problem, making the bug harder to diagnose.
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!