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

后端 未结 5 1030
鱼传尺愫
鱼传尺愫 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 03:02

    public class ZeroDivisionException extends ArithmeticException {
        // ...
    }
    
    if (denominator == 0) {
        throw new ZeroDivisionException();
    }
    

提交回复
热议问题