Class IntAdder

java.lang.Object
pro.teamlead.demo.sonatype.IntAdder

public class IntAdder extends Object
The Component class provides utility methods for arithmetic operations. This class demonstrates how to handle arithmetic overflow by throwing an exception.
  • Method Details

    • sum

      public static int sum(int a, int b)
      Sums two integers and checks for overflow.

      If adding the two integers results in an overflow, this method throws an ArithmeticException. This method demonstrates how to manually handle overflow conditions in integer arithmetic, which is not automatically checked by Java's standard arithmetic operations.

      Parameters:
      a - the first operand
      b - the second operand
      Returns:
      the sum of a and b
      Throws:
      ArithmeticException - if the result overflows the range of integers