Skip to main content

Practice · 2 of 3

Divide, but loudly

CHALLENGE
Difficulty: intermediate+25 XP

Write safeDivide(int a, int b) that returns (double) a / b - but throws ArithmeticException with a message containing "zero" when b is 0. A caller must be able to *catch* the failure, not discover a silent 0.

Back to lesson: Practice: Practice: Fail Well