How should I throw a divide by zero exception in Java without actually dividing by zero?

后端 未结 5 1026
鱼传尺愫
鱼传尺愫 2020-12-09 02:28

I have an I2C device that wants two inputs: a denominator and a numerator. Both are written to separate addresses, so no actual calculation (numerator/denominator

5条回答
  •  攒了一身酷
    2020-12-09 02:45

    Do this:

    if (denominator == 0) throw new ArithmeticException("denominator == 0");
    

    ArithmeticException is the exception which is normally thrown when you divide by 0.

提交回复
热议问题