private static int addAndCheck ( final int x , final int y ) { final long s = ( long ) x + ( long ) y ; if ( s < Integer . MIN_VALUE || s > Integer . MAX_VALUE ) { throw new ArithmeticException ( "overflow: add" ) ; } return ( int ) s ; }
Add two integers checking for overflow .