fork(12) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12.  
  13. int x = 2_000_000_000;
  14. int y = 1_000_000_000;
  15. try {
  16. int result = Math.addExact(x, y);
  17. System.out.println("The proper result is " + result);
  18. } catch(ArithmeticException e) {
  19. System.out.println("Sorry, " + e);
  20. }
  21.  
  22. }
  23. }
Success #stdin #stdout 0.15s 35780KB
stdin
Standard input is empty
stdout
Sorry, java.lang.ArithmeticException: integer overflow