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

statements after throw statement are still executed (win32)

XMLWordPrintable



      Name: krT82822 Date: 05/05/99


      If there is a while (for and do...while as well) statement in the same method
      as a throw, the variable assignments will still be executed after the exception
      is thrown.

      In the following example code one would expect the output to be true twice,
      that is not the case in fact the output will be true then false. When the first
      println method is executed flag of course is true then after the exception is
      thrown flag should still be true yet it will print out false within the catch block.

      Try moving the try block or the while block around a bit for the same yet
      interesting results as the try block does not have to be inside the while loop.

      This problem exists in the Windows VM in versions 1.1.7, 1.2 and 1.2.1.
      It has been tested under Visual Cafe 3.0, HP-UX and Solaris using the
      same .class file and did not exhibit this problem. Stepping through the
      code using the java debugger (via JPadPro) yields true then true.

      public class TestBug {
      static public void throwSomething() throws Exception {
      throw new Exception("something");
      }

      static public void main (String args[]) {

      boolean flag = false;

      System.out.println("comment out the while loop and try it again!");
      boolean done = false;
      while ( ! done) {
      done = true;
      try {
      flag = true;
      System.out.println(flag);
      throwSomething();
      flag = false;
      System.out.println(flag);

      } catch (java.lang.Exception e) {
      System.out.println(flag);
      }
      }
      }
      }

      /*
      java version "1.2.1"
      Classic VM (build JDK-1.2.1-A, native threads)

      java full version "JDK-1.2.1-A"
      */


      Output using JVM for WinNT v 1.2.1 :
      comment out the while loop and try it again!
      true
      false

      Output using JVM for HP-UX v 1.1.7:
      comment out the while loop and try it again!
      true
      true
      (Review ID: 57873)
      ======================================================================

            duke J. Duke
            kryansunw Kevin Ryan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: