Skip to content

Calculator.divide throws ArithmeticException instead of a clear IllegalArgumentException for a zero divisor #1

Closed

Description

@bingqin2

Calculator.divide throws an unchecked ArithmeticException when the divisor is 0.

Expected behaviour: divide should validate its input and throw IllegalArgumentException with the message divisor must not be zero before performing the division.

The failing test is CalculatorTest#should_reject_division_by_zero_with_a_clear_message in src/test/java/demo/CalculatorTest.java. The method to change is in src/main/java/demo/Calculator.java. Please keep the other arithmetic methods unchanged.

Activity

  1. added a commit that references this issue on Sep 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions