2 Replies Latest reply on Mar 22, 2010 2:40 PM by Sergey Anchipolevsky

    How to handle exit on exception?

    Sergey Anchipolevsky Newbie

      Hi Andrew!

       

      Is where a way of intercepting method exits on exceptions in 1.0.3? The documentation isn't clear enough in this regard. It could find only the following:

       

      [quote]

      An AT EXIT specifier locates a trigger point at each location in the trigger method where a
      normal return of control occurs (i.e. wherever there is an implicit or explicit return but not
      where a throw exits the method).

      ...

       

      An AT THROW specifier identifies a throw operation within the trigger method as the trigger
      point.

       

      [/quote]

       

      AT THROW doesn't help since it seems to handle only exceptions raised exactly in the trigger method (tying to athrow instructions I suppose), but skips ones raised from inner calls.

       

      Sergey

        • 1. Re: How to handle exit on exception?
          Andrew Dinn Master

          Hi Sergey,

           

          Is where a way of intercepting method exits on exceptions in 1.0.3? The documentation isn't clear enough in this regard. It could find only the following:

           

          Hmm, good question. The short answer is no.

           

          AT THROW doesn't help since it seems to handle only exceptions raised exactly in the trigger method (tying to athrow instructions I suppose), but skips ones raised from inner calls.

           

          Yes, that's correct. And you spotted that the problem is specifying precisely where you want the rule to be invoked. All I have to go on is the bytecode or line numbers. I can count athrow instructions and they correspond to throws in the original source so I can inject triggers before throws. However, it's much harder to decide where an exception might end up being generated below the trigger method.

           

          One of the things which makes this especially difficult is that the trigger injection has to occur before typechecking. A transformer agent is not able to rely on recursive classloading and reflection. If I am in the middle of transforming a trigger class and I try loading and resolving some related classes then that means those classes will not be able to be transformed. In fact in the worst case I may even lose the changes to the original class too.

           

          So, that rules out checking what exceptions  might be thrown by methods called from the trigger class. In fact it rules out doing any global analysis while transforming. I do build a control flow graph (CFG) for the trigger method but that is not enough to identify all the places where an exception might be thrown.

           

          I might possibly be able to install a catch-all handler around the whole method body and use that to drive rule execution. I;'ll have a think about whether that will be possible. However, I can say now for sure that it is going to be hard. The CFG code is the trickiest bit of Byteman so modifying it is a big job. Also, if I do put it into Byteman then it will likely only go into the 1.3 branch I am afraid. Of course, if you want to have a go at doing it in 1.0.x  I'd welcome your contribution and be happy to port it to 1.3.x :-)

           

          regards,

           

           

          Andrew Dinn

          • 2. Re: How to handle exit on exception?
            Sergey Anchipolevsky Newbie

            Yes, Andrew I understand the difficulties. That's why I turned to looking at byteman instead of processing bytecode myself . Hehe..

            I also was thinking about wrapping the whole method with try-finally. Of course it would be nice to have it in byteman. I'll consider your invitation to contribute :).

             

            Thank you for the answer!