3 Replies Latest reply on Jun 7, 2004 10:35 PM by chiba

    try catch in NewExpr

    vladsk

      Actualy I wanted to catch exceptions in during Object creation
      So I did:

      public class NewCodeConverter extends ExprEditor {

      public void edit(NewExpr expr) throws CannotCompileException {
      StringBuffer code = new StringBuffer(300);
      code.append("{ try ");
      code.append("{ $_ = $proceed($$); }");
      code.append("catch (OutOfMemoryErrore) {...} }");
      expr.replace(code.toString());
      }
      }

      but during execution I get:
      Exception in thread "main" java.lang.VerifyError:
      method: my_getmem signature: (I)V) Inconsistent stack height 0 != 2

      could you help?
      Regards,
      VladS
      Also are thre a bugs database?

        • 1. Re: try catch in NewExpr
          chiba

          The reason of that exception is that $_ is not initialized if an OutOfMemoryError exception is thrown.
          So the problem should be fixed if you assign some value to $_ in the catch block.

          I have also modified Javassist so that $_ is automatically initialized. If you use Javassist directly downloaded from the CVS head (or use an upcoming beta 3 or later), your code above should run without any problem.

          • 2. Re: try catch in NewExpr
            vladsk

            During last week I made instrumentaton of a large project.
            And some time I have seen java.lang.VerifyError at run time.
            Is it posible to run code verification before saving class file?

            • 3. Re: try catch in NewExpr
              chiba

              Currently, no.
              I'm putting error checking code to avoid
              wrong instrumentation, but it is not a simple
              thing to produce useful error messages.

              Also, I have to consider the range of possible
              instrumentation. For example, changing
              a public method to be private would cause
              VerifyError if some methods in another
              class access that method. Detecting this
              error before saving a class file is a complicated
              task under the current architecture of Javassist.

              It would be great if you give me back your
              experiences of VerifyError. I can improve
              erorr checking code.