6 Replies Latest reply on May 19, 2016 3:24 PM by chiba

    try ... finally

    hlship

      The docs for 3.0 still state that try ... finally is not supported. Is this true? I would very much like to use Javassist for a particular application, but being able to use a finally clause is critical.

        • 1. Re: try ... finally
          chiba

          OK, I'll put finally support in my TODO list.

          • 2. Re: try ... finally
            chiba

            Finally, finally clauses have been supported. :)

            • 3. Re: try ... finally
              alexandnpu

              chiba, in what kind of support?

              I've recently started to use javassist. and I found that try..finally is not executed when an exception occured.

               

              below is my usage:

               

              ==================================================================

              String methodBody = "

                 try {

                     %s($$);

                 } finally {

                     // here is my own logic   #1

                 }

              ";

              CtMethod methodNew = CtNewMethod.copy(methodOriginal, methodName, ctClass, null);

              methodNew.setBody(methodBody);

              ctClass.addMethod(methodNew);

              ====================================================================

               

              for this code, I found that if there is no exception, the code in the finally block will execute.

              if there IS an exception occurs, the finally block won't execute.

               

              is this expected ? or it is due to my wrong usage or setting?

              my javassist version is:

               

              <dependency>

                 <groupId>org.javassist</groupId>

                 <artifactId>javassist</artifactId>

                 <version>3.20.0-GA</version>

              </dependency>

              • 4. Re: try ... finally
                alexandnpu

                false alarm!

                 

                it turns out to be the fault of my testing code.

                • 5. Re: try ... finally
                  chiba

                  OK