Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8261397

try catch Method failing to work when dividing an integer by 0

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b11
    • CPU:
      x86_64
    • OS:
      os_x

      Backports

        Description

        ADDITIONAL SYSTEM INFORMATION :
        macOS Big Sur 11.2

        A DESCRIPTION OF THE PROBLEM :
        Anytime a divide any integer value in a System.out.println() by 0, utilizing a try-catch statement to deal with this ArithmeticException, a message pops up on my screen stating "A fatal error has been detected by the Java Runtime Environment." Another thing, is whenever I write System.out.println(1/0); or any integer being divided by 0, my entire IDE crashes immediately without the program even being run (Eclipse).

        ERROR MESSAGES/STACK TRACES THAT OCCUR :
        #
        # A fatal error has been detected by the Java Runtime Environment:
        #
        # SIGFPE (0x8) at pc=0x000000011778d168, pid=1403, tid=7427
        #
        # JRE version: Java(TM) SE Runtime Environment (15.0.1+9) (build 15.0.1+9-18)
        # Java VM: Java HotSpot(TM) 64-Bit Server VM (15.0.1+9-18, mixed mode, sharing, tiered, compressed oops, g1 gc, bsd-amd64)
        # Problematic frame:
        # j Arithmetic_Exception.main([Ljava/lang/String;)V+4
        #
        # No core dump will be written. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
        #
        # An error report file with more information is saved as:
        # /Users/shaheer/eclipse-workspace/Handling_Exception_(Throws)/hs_err_pid1403.log
        #
        # If you would like to submit a bug report, please visit:
        # https://bugreport.java.com/bugreport/crash.jsp
        #


        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Int x=1; // Can be any integer
        int y=0;
        System.out.println(x/y) // Even a try-statement cannot deal with this

        //Second bug
        System.out.println(1/0) //Can be any integer as the numerator.
                                   // Any time this gets written out, the entire IDE will crash without even running the program

        ACTUAL -
        #
        # A fatal error has been detected by the Java Runtime Environment:
        #
        # SIGFPE (0x8) at pc=0x000000011778d168, pid=1460, tid=8963
        #
        # JRE version: Java(TM) SE Runtime Environment (15.0.1+9) (build 15.0.1+9-18)
        # Java VM: Java HotSpot(TM) 64-Bit Server VM (15.0.1+9-18, mixed mode, sharing, tiered, compressed oops, g1 gc, bsd-amd64)
        # Problematic frame:
        # j Arithmetic_Exception.main([Ljava/lang/String;)V+4
        #
        # No core dump will be written. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
        #
        # An error report file with more information is saved as:
        # /Users/shaheer/eclipse-workspace/Handling_Exception_(Throws)/hs_err_pid1460.log
        #
        # If you would like to submit a bug report, please visit:
        # https://bugreport.java.com/bugreport/crash.jsp
        #

        ---------- BEGIN SOURCE ----------
        public class Arithmetic_Exception {
        public static void main(String[] args) {
        int x=5;
        int y=0;
        try {System.out.println(x/y);}
        catch(ArithmeticException A) {System.out.println("y cannot be 0");}
        }
        }
        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        I haven't found any workaround, I simply just avoid it. Albeit, this hinders me a lot when I am working.

        FREQUENCY : always


          Attachments

            Issue Links

              Activity

                People

                Assignee:
                gziemski Gerard Ziemski
                Reporter:
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                14 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved: