Skip to main content

Practice ยท 2 of 3

Divide, but loudly

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.

Difficulty: intermediate

Back to lesson: Practice: Practice: Fail Well