3

In my code I am trying to handle and Arithmetic Exception in eclipse java. My code is running fine in windows but its giving some Fatal error in Mac although it is working fine for other kinds of exception like IndexOutOfBound. And I am getting no idea that what is the problem.So below is my code and error that is showing.

public class ExceptionHandling {

public static void main(String[] args) {

    try{
         int num1=30, num2=0;
         int output=num1/num2;
         System.out.println ("Result: "+output);
      }
      catch(ArithmeticException e){
         System.out.println ("You Shouldn't divide a number by zero");
      }

   }

}

enter image description here

Thankyou it might seems to be a silly question but I would appreciate your help thanks in advance.

Jim Garrison
  • 85,615
  • 20
  • 155
  • 190
  • [Please do not upload images of code/errors when asking a question.](//meta.stackoverflow.com/q/285551) – Joachim Sauer Apr 22 '21 at 18:31
  • There are lots of SIGFPE (floating point exception) bugs in the Java bug database. Are you running on an Intel or Apple M1 Mac? Search for "java 11 bug sigfpe" for an entertaining list of problems. BTW, thanks for including a [mre]. Also, this works fine in Java 15, so upgrade if you are not constrained to Java 11. – Jim Garrison Apr 22 '21 at 18:34
  • @JoachimSauer I'm not sure the flagged dup target is applicable. According to the header line the architecture is amd64, not aarch64. As I noted in an earlier comment, there are lots of SIGFPE bugs in the database, and this could be any of them. – Jim Garrison Apr 22 '21 at 18:44
  • @JimGarrison: it's quite possible that I picked a wrong dupe, but it looks to me like both JVMs rn in `bsd-amd64`. In fact neither question mentions `aarch64`, as far as I see. – Joachim Sauer Apr 22 '21 at 18:45
  • @JimGarrison Thanks, on updating java to version 16 it has start working and throwing exception correctly but still when I write divide by zero directly instead of storing it in a variable and then performing operation eclipse gets crashe. Like if I write a=10 and b=0 and a/b then eclipse handles it but if I write 10/0 directly then eclipse gets crashed immediately any suggestions for it? – Love Kaushik Apr 24 '21 at 07:33

0 Answers0